Search code examples
asp.netdependency-injectioninversion-of-controlglobalization

Is is possible to programmatically change the resourceProviderFactoryType?


I have a custom implementation of IResourceProvider and ResourceProviderFactory. Now the default way of making sure ASP.NET uses these custom types is to use the web.config and specify the factory like so:

<globalization resourceProviderFactoryType="Product.Globalization.TranslationResourceProviderFactory" />

This works perfectly, except that in my resource provider I need database access. I want to use my IoC-container(Ninject) to inject the repositories needed to access this data into the CustomResourceProvider. But how am I going to do this? I have no control over the instantiation of the factory, so the factory can't get a reference to my IoC.

Is there any way to register a custom provider programmatically, in for example the Global.asax?


Solution

  • Your custom implementation of ResourceProviderFactory could use the DI framework to retrieve the instance of IResourceProvider.