I’ve frequently seen a question arise about why anyone would use an open-source
dependency injection framework like AutoFac when Microsoft provides
Microsoft.Extensions.DependencyInjection
(MEDI). Isn’t that good enough?
It’s a fair question. MEDI is a capable dependency injection container and will
support most application needs. However, I still find it worthwhile to plug
AutoFac in.
Microsoft created MEDI so that framework and library authors could depend on
some basic dependency injection capabilities without writing adapters for every
popular DI container. Microsoft specified base-level functional expectations,
but application developers that wanted more power could use a different tool as
long as it could conform to the protocol Microsoft specified. As a result, the
MEDI provides a limited feature set by design.
I frequently want more robust capabilities and will install AutoFac to get them.
The rest of this post will highlight some of the features of AutoFac that I
particularly like. While not provided out of the box, Developers can emulate
many of these features with MEDI, though perhaps clumsily. Some have no analog
at all. Sample code is also on GitHub.