-1
In my Application layer, I have the following classes:
public class AutoMapperConfig
{
public static MapperConfiguration RegisterMappings()
{
return new MapperConfiguration(cfg =>
{
cfg.AddProfile(new DomainToViewModelMappingProfile());
cfg.AddProfile(new ViewModelToDomainMappingProfile());
});
}
}
public class DomainToViewModelMappingProfile : Profile
{
public DomainToViewModelMappingProfile()
{
CreateMap<Customer, CustomerViewModel>();
}
}
public class ViewModelToDomainMappingProfile : Profile
{
public ViewModelToDomainMappingProfile()
{
CreateMap<CustomerViewModel, RegisterNewCustomerCommand>()
.ConstructUsing(c => new RegisterNewCustomerCommand(c.Name, c.Email, c.BirthDate));
CreateMap<CustomerViewModel, UpdateCustomerCommand>()
.ConstructUsing(c => new UpdateCustomerCommand(c.Id, c.Name, c.Email, c.BirthDate));
}
}
In my Asp.net MVC layer, I have the Startup.Cs class that through the services.Addautomapper() method; initializes my Automapper configuration classes, only that it calls the method and does not go through the classes cited above. Consequently, when I send to save a record to my bank, there is an error in my Automapper-related controller:
Error: "+ $Exception {Automapper.Automapperconfigurationexception: Unmapped Members Were found. Review the types and Members Below. Add a custom Mapping Expression, ignore, add a custom resolver, or Modify the source/Destination type
For no matching constructor, add a no-Arg ctor, add optional Arguments, or map all of the constructor Parameters
Customerviewmodel -> Registernewcustomercommand (Destination Member list) Systemscommercial.Application.Viewmodels.Customerviewmodel -> Systemscommercial.domain.Commands.Customer.Registernewcustomercommand (Destination Member list)
Unmapped properties: Timestamp Validationresult Messagetype Aggregateid
at AutoMapper.ConfigurationValidator.AssertConfigurationIsValid(IEnumerable`1 typeMaps) lambda_method(Closure , Customerviewmodel , Registernewcustomercommand , Resolutioncontext ) lambda_method(Closure , Object , Object , Resolutioncontext ) At automapper.Mapper.Automapper.IMapper.Map[Tdestination](Object source) at SistemaComercial.Application.Services.CustomerAppService.Register(CustomerViewModel customerViewModel) in C:\Users\jalbe\Desktop\New_Project\SistemaComercial\src\SistemaComercial.Application\Services\CustomerAppService.cs:line 46 at SistemaComercial.Presentation.Web.MVC.Controllers.CustomerController.Create(CustomerViewModel customerViewModel) in C:\Users\jalbe\Desktop\New_Project\SistemaComercial\src\SistemaComercial.Presentation.Web.MVC\Controllers\CustomerController.cs:line 62 lambat da_method(Closure , Object , Object[] ) At Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] Parameters) At Microsoft.AspNetCore.Mvc.Internal.Controlleractioninvoker.d__12.Movenext()} Automapper.Automapperconfigurationexception "
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAutoMapper(); //Jalber
// Adding MediatR for Domain Events and Notifications
services.AddMediatR(typeof(Startup)); //Jalber
// .NET Native DI Abstraction
RegisterServices(services); //Jalber
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
private static void RegisterServices(IServiceCollection services)
{
// Adding dependencies from another layers (isolated from Presentation)
NativeInjectorBootStrapper.RegisterServices(services);
}
}
How do I fix it?
I noticed..... Very good!!!
– Master JR