I have an WebApi application using OWIN and Autofac. Although controllers and parameters get resolved correctly, I would like to be able to use
OwinContext.Get<type> to resolve types registered with Autofac. Is that posible?
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
By example, I registered
builder.Register<IAppConfiguration>(c => new AppConfig()); and I'd like to resolve it using
Best How To :
IOwinContext.Get uses the
Environment dictionary, resolving objects registered directly with Owin, it does not take into account Autofac container.
I managed to do it by accessing the Autofac OwinLifetimeScope in the Environment property and using the scope to resolve the service.
You can access the LifetimeScope using this code
You should check for nulls and write it in a better way, as Extension method maybe.