loading providers dynamically using Autofac
I'm using Autofac in my project
I have different kind of providers such as data or logging , etc. thease providers are set in the web.config sections and I have a default provider for each section.so my question is how can I use autofac to load my providers dynamical开发者_C百科ly.shoud I refactor and change my providers implementions?
The provider pattern is in fact a focussed IoC implemention by itself. Because it has a facade and a configuration model of its own, it makes it hard to control lifestyle by Autofac or any other DI container.
What you can and should do, is prevent the provider's facade (such as the static Membership
class of the ASP.NET Membership provider model) to be called directly by the application. Instead register the provider (i.e. MembershipProvider
base class in case of the membership model) in Autofac and let it be injected into the application. For instance:
builder.Register<MembershipProvider>(c => Membership.Provider);
精彩评论