2

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 the 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.

Community
  • 1
  • 1
user748857
  • 21
  • 1

1 Answers1

1

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.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736