How to scan and auto-configure profiles in AutoMapper?

后端 未结 8 656
花落未央
花落未央 2020-12-24 02:50

Is there any way to auto-configue Automapper to scan for all profiles in namespace/assembly? What I would like to do is to add mapping profiles to AutoMapper from given asse

8条回答
  •  -上瘾入骨i
    2020-12-24 02:56

    In .NET Core:

        services.AddSingleton(this.CreateMapper());
        //...
        private IMapper CreateMapper()
                => new MapperConfiguration(config => config.AddMaps(Assembly.Load("Your.Project.App")))
                .CreateMapper();
    

提交回复
热议问题