✅ How to register all Automapper profiles from one project in the Startup class of a second project
Hi friends, I have a solution with the structure in the screen-shot attachement,
I use Automapper in
I use Automapper in
CQRSCore
and WEB
projects, the CQRSCore
is a class library, and the WEB
project is an ASP.Net Core 7
project.
Both in the CQRSCore
and WEB
projejcts I use Automapper profiles, and I'm looking for a simple way that using only the assembly to register all the profiles without register each one alone.
So I tried :
But stiill getting the following error:
Mapping types: Branch -> BranchDto Core.Entities.Branch -> CQRSCore.DTOs.Branch.BranchDtoI hope soneone please to provide a help ifi he had this experience before. Massive thanks in advance.
![](https://utfs.io/f/bfc982b8-753e-4ea2-a572-dcc6d80a90f4-1nq2cb.png)
5 Replies
well
Assembly.GetExecutingAssembly(), typeof(Startup).Assembly
probably refer to the same assembly, so you should probably pass in a reference to the other assembly that contains the mappersThanks for your time to help, I appreciate,
Please do you know what method should I use to reference it especially it is a
Class library
and doesn't contain any Startup
?I've used
Assembly.Load("AssemblyName")
you can use typeof(SomeTypeInOtherAssembly).Assembly
as well, don't really know what is considered best practice for thatTypeof(startup).assembly is best practice afaik; recommended by Microsoft
I fixed it by using
II appreciate your help @Deluxe , massive thanks