j0w
j0w

Reputation: 545

How to properly map entities in a business layer?

I'm working in a multiple layers application ( basically web, data, business). I'm trying to properly pass objects between the layers so, for the web, I used AutoMapper to pass a DTO to my business layer. Everything went ok because I'm in the web layer which has the Startup.cs so I could add the following services.AddAutoMapper(typeof(Startup)); in ConfigureServices.

Question is, can I do the same to map the Entity I retrieve from DB to a BusinessObject, in my Business layer that doesn't have the Startup.cs?

How do I configure AutoMapper in that case?

Upvotes: 0

Views: 228

Answers (1)

Edward
Edward

Reputation: 29986

For services.AddAutoMapper(typeof(Startup));, params Type[] profileAssemblyMarkerTypes is the types, it will loop the types in this assemply to find the Profile.

public static IServiceCollection AddAutoMapper(this IServiceCollection services, params Type[] profileAssemblyMarkerTypes)
        => AddAutoMapperClasses(services, null, profileAssemblyMarkerTypes.Select(t => t.GetTypeInfo().Assembly));

Not sure whether you add the profile for DB to a BusinessObject in web, data or business project, you just need to configure the type whose assemply contains the profile in web project.

Upvotes: 2

Related Questions