dependency injection using unity on custom session store provider
I made a custom SessionStateStore provider, however the dependencies were not resolving. I used Unity for DI.
I googled a lot about this problem and got some useful hints, but still I can't get it right.
- the providers are constructed and managed by the framework, and there is no opportunity for us to intercept that construction to provide additional dependency injection
- override th开发者_运维百科e Initialize() method in your custom provider, and do the dependency injection there
There's a similar problem and a decent solution here and here(StructureMap, not Unity), but I can't get it right.
Please help. Thanks.
Providers are really painful things. There's really no nice way to address this problem, but a practical way is to handle the provider as a Composition Root - in other words, as if it was the entry point of the application. Within the provider you can compose all of your services.
If you use a DI Container (like Unity) you can store the container instance in HttpContext and get it from there to compose your object graph from within the provider.
精彩评论