autofac

Caliburn.Micro + Autofac bootstrapping

对着背影说爱祢 提交于 2019-12-04 11:05:24
I have a project with Caliburn.Micro, and I'm trying to port from its SimpleContainer to Autofac . I'm using this code , that is an updated version of the code in this guide . Using SimpleContainer I simply did (inside the bootstrapper) protected override void OnStartup(object sender, System.Windows.StartupEventArgs e) { this.DisplayRootViewFor<IScreen>(); // where ShellViewModel : Screen } Now this doesn't work anymore, so what should I do to integrate Autofac with Caliburn.Micro ? There are a couple of things wrong with your solution. Firstly, nothing invokes your AppBootstrapper . This is

How do I resolve Dependency Injection in MVC Filter attributes

…衆ロ難τιáo~ 提交于 2019-12-04 10:36:42
问题 I have a custom attribute class derived from AuthorizationAttribute, which performs custom security on controller actions. The OnAuthorizationCore method depends on various other components (e.g. DAL) in order to ajudicate whether a user can invoke an action. I'm using Autofac for dependency injection. The ExtensibleActionInvoker claims to be able to perform property injection on action filters. Setting an attribute's properties at runtime (which seems like a bad idea) will work in a simple

How to use autofac in an UWP app?

余生颓废 提交于 2019-12-04 09:59:27
问题 I am using autofac in an UWP application. In my App instance, I am setting up the dependency, like this: public sealed partial class App { private readonly IFacade m_facade; public App() { InitializeComponent(); m_facade = InitializeDependencies(); Suspending += OnSuspending; } private IFacade InitializeDependencies() { var containerBuilder = new ContainerBuilder(); // Registers all the platform-specific implementations of services. containerBuilder.RegisterType<LoggingService>() .As

Autofac sub-dependencies chain registration

和自甴很熟 提交于 2019-12-04 08:39:34
Question How do I construct an AutoFac ContainerBuilder such that my sub-dependencies are correctly resolved (assuming more than one concrete implementation of an interface)? Default registration/resolve will not work because I have more than one concrete implementation of a sub-dependency, and the sub-dependency resolution is dependent on the resolution of the primary object. In all cases I wish to use constructor injection. Scenario For example, lets say I need to print a receipt, so I create an interface called IReceipt, with one method, called PrintReceipt(). But I need to print 3 kinds of

Autofac - resolving dependencies in multi thread environment

冷暖自知 提交于 2019-12-04 07:57:34
public class MultithreadTester { public void Run() { var builder = new ContainerBuilder(); builder.RegisterType<ManualWork>().As<IWork>(); builder.RegisterType<ColabManualWork>().As<IColabWork>(); builder.RegisterType<RelaxAfterManualWork>().As<IRelax>(); var container = builder.Build(); //#1 - Simple single thread using (var scope = container.BeginLifetimeScope()) { var work = scope.Resolve<IWork>(); work.DoWork(); } //#2 - Resolving dependecies in worker threads in scopes of these threads without passing lifetime scopes are container into implementation using (var scope = container

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

风流意气都作罢 提交于 2019-12-04 07:33:35
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<RoleManager<IRole>>(); builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IRole>>(); builder

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

冷暖自知 提交于 2019-12-04 07:15:28
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(ctx => { var typeArray = ctx.RequestedType.GetGenericArguments(); // this can be memoized var

Access or get Autofac Container inside a static class

雨燕双飞 提交于 2019-12-04 07:13:24
I need to get or access to my IoC container in a static class. This is my (simplified) scenario: I register dependencies for ASP .net Web Api in a Startup class (but also I do this for MVC or WCF. I have a DependecyResolver project, but for simplicity, consider the following code) // Web Api project - Startup.cs public void Configuration(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); var builder = new ContainerBuilder(); // ... Omited for clarity builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .AsClosedTypesOf(typeof(IHandle<>))

No IUserTokenProvider is registered when using dependency injection

ぐ巨炮叔叔 提交于 2019-12-04 06:51:28
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(); // REGISTER DEPENDENCIES containerBuilder.RegisterType<SampleDataContext>() .As<DbContext>()

Get all registered implementations of an interface in Autofac

笑着哭i 提交于 2019-12-04 06:34:55
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? I figured this out -- var types = scope.ComponentRegistry.Registrations .SelectMany(r => r.Services.OfType<IServiceWithType>(), (r, s) => new { r, s }) .Where(rs => rs.s.ServiceType.Implements<T>()) .Select(rs => rs.r.Activator.LimitType); With