Configure Autofac Container for background thread
I have an asp.net MVC site which has many components registered using an InstancePerHttpRequest scope, however I also have a "background task" which will run every few hours which will not have an httpcontext. I would like to get an instance of my IRepository which has been registered like this builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)) .InstancePerHttpRequest(); How do I do this from a non http context using Autofac? I think the IRepository should use the InstancePerLifetimeScope There are several ways of how you can do that: The best one in my opinion. You can