综合编程

AutoMapper extensions for Microsoft DI 5.0 released

微信扫一扫,分享到朋友圈

AutoMapper extensions for Microsoft DI 5.0 released
0

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:

services.AddMvc();  
services.AddAutoMapper();

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.

阅读原文...


微信扫一扫,分享到朋友圈

AutoMapper extensions for Microsoft DI 5.0 released
0

Avatar

KeyCDN Launches POP in Auckland

上一篇

Quickly Building RESTful UI’s in NuxtJS

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

AutoMapper extensions for Microsoft DI 5.0 released

长按储存图像,分享给朋友