开发者

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.

  1. 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
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜