AutoMapper extensions for Microsoft DI 5.0 released

综合编程 2018-07-19 阅读原文

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
inject an IMapper
for instance mapping or IConfigurationProvider
for LINQ projections ( ProjectTo

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 Mapper
class with an IMapper
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.

责编内容by:Jimmy Bogard 【阅读原文】。感谢您的支持!


ABP框架 – 介绍 在14,15年间带领几个不同的团队,交付了几个项目,在这个过程中,虽然几个项目的业务不一样,但是很多应用程序架构基础性的功能却是大同小异,例如认证、授权、请求验...
Contoso University Examples with CQRS, MediatR, Au... I was a bit surprised yesterday to see Scott Hanselman's post on my Contoso ...
Importing Automapper into a web storage project an... I am trying to use the ts automapper libary in an Angular2 webpack project b...
AutoMapper – Declarative data mapper for PHP 7 AutoMapper can map data from array/object to existing array/object or marsh...
Automapping has no mapped ID My Entity Class: public class Building { /// /// interna...