How can register profiles in Automapper from different assemblies?

…衆ロ難τιáo~ 提交于 2021-01-29 11:21:14

问题


I have an application (NET Core) with many assemblies:

  • WebAPI (contain view models and consume DTO)
  • Services (contain DTO and consume Domain entities)

On WebAPI assembly I registered automapper profiles automatically with this line:

services.AddAutoMapper();

With this line I can convert view models to DTO (and backwards)

But I need register profiles located on Services layer to convert DTO to Domain entities (and backwards)

Evidently, Automapper not found this profiles.

What's the best way to register profiles from different assemblies?


回答1:


I use services.AddAutoMapper(params Assembly[] assemblies).

for example:

services.AddAutoMapper(
    typeof(Startup).GetTypeInfo().Assembly, 
    typeof(Class_In_Other_Assembly).GetTypeInfo().Assembly
);


来源:https://stackoverflow.com/questions/57498337/how-can-register-profiles-in-automapper-from-different-assemblies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!