Hot off the presses, with some pretty big breaking changes. For the unfamiliar, the AutoMapper.Extensions.Microsoft.DependencyInjection
package is the extension to the MS DI libraries used by ASP.NET Core and others. It lets you do:
And this package finds all AutoMapper configuration in the current AppDomain, or assemblies you specify, configure everything, and register the AutoMapper-specific services with the container.
In the past, I've supported both the static- and instance-based means of using AutoMapper with this library. However, because of a number of issues, the static version is fundamentally incompatible with dependency injection, making it far to easy to make mistakes.
This version removes the support for static usage of AutoMapper, and you now must
for instance mapping or
for LINQ projections (
It's a bit of a breaking change, but I think for the better as it removes this wonky static global instance of AutoMapper that's at odds with how anyone using ASP.NET Core/MS DI deals with any other dependency.
To migrate, you'll need to replace all instances of using the static
class with an
dependency. I've also removed the configuration option to force the instance-based registration, so if you use that, just remove it.
The moral of the story - if you're doing DI, don't go halfway.