0

I'm just starting to work with ASP.Net MVC Core and am trying to understand some of the differences between that and ASP,Net MVC Framework.

I use the Mapster library to organize the mappings between my data objects and the view models. In the old world I would create a Mapping Configuration file with my DTO to viewmodel mappings and then call that at startup. Is there a best practice way to do this in the Core world? I assume something that gets called in the startup class?

Any suggestions or examples would be appreciated.

John S
  • 7,909
  • 21
  • 77
  • 145

1 Answers1

0

In asp.net core, you could put your mapping code in startup Configure method

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        TypeAdapterConfig<Employee, EmployeeViewModel>.NewConfig()
                        .Map(dest => dest.Name, src => src.FirstName + " " + src.LastName);
        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }

Refer to https://www.codeproject.com/Articles/1249355/Mapster-Your-Next-Level-Object-to-Object-Mapping-T

Ryan
  • 19,118
  • 10
  • 37
  • 53