How would you use Autofac for the DI? #68
-
I have a preference of using Autofac over Microsoft's DependencyInjection because of the registration tooling. I see some places that hint as how they could be implemented but I'm not sure what would be the best way to get Autofac injected into the system. Could you please give me some pointers? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Great question! The Statiq internals are (mostly) designed around the Microsoft.Extensions.DependencyInjection abstraction layer and don't do anything very exotic beyond lifetime management. There's a few places like the Razor module where the container is cracked open a bit and the service descriptors are messed with, but even that should be okay since it's an abstraction over the container implementation (I.e. Autofac should be providing implementations of all the service descriptor bits). I got curious and did a search for everywhere an actual
I'm going to guess you're using the bootstrapper? If so, the trick is to derive your own bootstrapper class from To use Statiq Web with your own bootstrapper that uses a different DI container you might end up with something like this:
Let me know if you have any trouble! |
Beta Was this translation helpful? Give feedback.
Great question! The Statiq internals are (mostly) designed around the Microsoft.Extensions.DependencyInjection abstraction layer and don't do anything very exotic beyond lifetime management. There's a few places like the Razor module where the container is cracked open a bit and the service descriptors are messed with, but even that should be okay since it's an abstraction over the container implementation (I.e. Autofac should be providing implementations of all the service descriptor bits).
I got curious and did a search for everywhere an actual
Microsoft.Extensions.DependencyInjection.ServiceCollection
implementation is instantiated and was happy to see past @daveaglick had already thro…