AutoFac / Unity Container – Dependency Injection with multiple implementations
I am going to work with Dependency Injection for a ASP.NET Web API project.
I am going to work with Dependency Injection for a ASP.NET Web API project.
I’m trying to use OWIN, SignalR and Autofac in a single project.
I’m still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places in a web application.
I am new to IoC and am using Autofac in my current project.
Using Autofac in ASP.NET along with the ContainerDisposalModule, how can i support fire and forget calls that have component dependencies that need to be resolved? The problem I’m running into is that the ASP.NET request completes and disposes the lifetime scope of the request before the Task is ran, so any components that need to be resolved in the new thread fail with the message “Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed”. What’s the best way to support fire and forget call using Autofac in ASP.NET? I don’t want to delay the request to perform certain tasks which can be done on background threads.
I have a situation where I need to manually instantiate some objects in Application_BeginRequest that are dependent on some of the same components that I’ve registered with Autofac. I’d like to use the same instances of components that I’ve registered with Autofac with InstancePerLifetimeScope for injection into my MVC and WebAPI controllers. My config for both MVC and Web API works as expected, and an example of a component registration looks like so: