1. Create a new class
Using AutoMapper; Using Yourmodels; Using Yourviewmodels; Namespace YourNameSpace {public class Automapperprofileconfiguration:profile {protected override void Configure () {Cr Eatemap<application, applicationviewmodel> (); Createmap<applicationviewmodel, application> (); ... } } 2, adding mapperconfiguration properties to Startup.cs
Private mapperconfiguration _mapperconfiguration {get; set;} 3, increasing in the startup method in Startup.cs
_mapperconfiguration = new Mapperconfiguration (cfg => {cfg). Addprofile (New Automapperprofileconfiguration ()); }); 4. Increase in configureservices ()
Services. Addsingleton<imapper> (SP => _mapperconfiguration.createmapper ()); 5. Use
Using AutoMapper; Using ... namespace YourNameSpace {public class Applicationscontroller:basecontroller {[fromservices] private Imapper _mapper {get; set;} [Fromservices] Private iapplicationrepository _applicationrepository {get; set;} Public Applicationscontroller ( Imapper Mapper, Iapplicationrepository applicationrepository) {_mapper = mapper; _applicationrepository = Applicationrepository; }//Get:applications public async task<iactionresult> Index () {ienumerable<application> applications = Awai T _applicationrepository.getforidasync (...); if (applications = null) return Httpnotfound (); List<applicationviewmodel> ViewModel = _mapper. Map<list<applicationviewmodel>> (applications);