autofac

Is it possible to register an open generic delegate in autofac?

99封情书 提交于 2019-12-06 02:43:50
问题 I want to register a generic delegate that resolves itself at runtime, but I cannot find a way to do this on generics. Given a delegate that looks like this: public delegate TOutput Pipe<in TInput, out TOutput>(TInput input); And given a discretely registered delegate that look like this: public class AnonymousPipe<TInput, TOutput> { public Pipe<TInput, TOutput> GetPipe(IContext context) {...} I want to register a function along the lines of this: builder.RegisterGeneric(typeof(Pipe<,>)).As

The type RoleStore<IdentityRole> is not assignable to service IRoleStore<IRole>

不羁的心 提交于 2019-12-06 02:43:16
问题 I'm trying to set up dependency injection with Autofac for project using MVC5 and EF6. I'm having a hard time figuring out how to decouple correctly the EntityFramework.RoleStore<EntityFramework.IdentityRole> implementation. I would like have dependency only on Identity.IRoleStore<Identity.IRole> but I'm aware that for generic classes I need to specify the concrete implementation, not the interface. This is what I tried: builder.RegisterType<IdentityRole>().As<IRole>(); builder.RegisterType

Net Core: access to appsettings.json values from Autofac Module

情到浓时终转凉″ 提交于 2019-12-06 02:32:48
问题 AspNet core app 1) Autofac module like that public class AutofacModule : Module { protected override void Load(ContainerBuilder builder) { //Register my components. Need to access to appsettings.json values from here } } 2) Module from step№1 registered into Startup.cs public void ConfigureContainer(ContainerBuilder builder) { builder.RegisterModule(new AutofacModule()); } How to access to appsettings.json values from AutofacModule ? I need that for create my objects inside AutofacModule and

Using a Custom Endpoint Behavior with WCF and Autofac

拟墨画扇 提交于 2019-12-06 02:31:06
问题 I'm trying to implement a UoW like shown here: http://blog.iannelson.systems/wcf-global-exception-handling/ But I can't for the life of me figure out how to wire it up with Autofac. I have absolutely no idea where to start. I've got WCF working fine with Autofac from using http://autofac.readthedocs.org/en/latest/integration/wcf.html But to inject or add the IEndpointBehavior? No idea... If there's a better way to implement a UoW I would like to hear. Edit: For now I've just done: builder

Autofac - resolving component with parameters dynamically

瘦欲@ 提交于 2019-12-06 02:29:02
问题 I have a class that takes an interface as a constructor argument. There are two implementations of this interface and I want to decide what implementation to use at runtime based on a variable. The problem is that the class above is deep in an object heirarchy that is resolved by Autofac and so I can't pass in the argument. Somehing like below is what I am trying to achieve. public interface IInterface1 {} public interface IInterface2 {} public class Class1 : IInterface2 { public Class1

Scope error when using Autofac with SignalR

寵の児 提交于 2019-12-06 02:23:40
问题 I'm trying to inject an HttpContextBase in my SignalR hub: public class EventHub : Hub, IDisconnect { private readonly HttpContextBase _httpContextBase; public EventHub(HttpContextBase httpContextBase) { _httpContextBase = httpContextBase; } [...] } The registration code looks like this: private static void InitAutofac() { var builder = new ContainerBuilder(); var assembly = typeof (MvcApplication).Assembly; builder.RegisterControllers(assembly).PropertiesAutowired(); builder.RegisterModule

Configuring AutoMapper to fulfil ITypeConverter<,> constructor dependecies with Autofac

倾然丶 夕夏残阳落幕 提交于 2019-12-06 02:18:19
My first time working with Autofac to inject AutoMapper's IMapper interface into classes that have an object mapping requirement. I have made some progress, with a little help , getting the various dependencies added to AutoMapper's register using Assembly Scanning: builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .AsClosedTypesOf(typeof(ITypeConverter<,>)) .AsImplementedInterfaces(); builder.RegisterAssemblyTypes(typeof(AutoMapperExtensions).Assembly) .AssignableTo<Profile>().As<Profile>(); builder.Register(context => { var profiles = context.Resolve<IEnumerable<Profile>

No IUserTokenProvider is registered when using dependency injection

邮差的信 提交于 2019-12-06 01:59:33
问题 I got an error when my GeneratePasswordResetTokenAsync() method is call. I configured autofac with owin identity. The error is : No IUserTokenProvider is registered when using dependency injection In my sample.web project there is a AutofacConfig.cs file where I register signinmanager and usermanager which I created in sample.repository project. AutofacConfig.cs public class AutofacConfig { public static Autofac.IContainer RegisterDependencies() { var containerBuilder = new ContainerBuilder()

Get all registered implementations of an interface in Autofac

大憨熊 提交于 2019-12-06 01:47:45
问题 I need to get, from an IComponentContext , a list of registered Type 's that implement a particular interface. I don't want actual instances of the types, but rather a list of Type of which I could get instances. I want to use this list to generate subscriptions on a message bus. How do I get all registered implementations of an interface in Autofac? 回答1: I figured this out -- var types = scope.ComponentRegistry.Registrations .SelectMany(r => r.Services.OfType<IServiceWithType>(), (r, s) =>

Castle Windsor Typed Factory Facility equivalents

与世无争的帅哥 提交于 2019-12-05 22:59:45
问题 do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor? e.g. if I am using an abstract factory pattern in a WPF application: public class MyViewModel { private IAnotherViewModelFactory factory; public void ShowAnotherViewModel() { viewController.ShowView(factory.GetAnotherViewModel()); } } I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container