Our team has inherited a MVC project that uses Automapper. We will be building on top of this project for enhancements. Overall, it's coded very well and will be a good framework for us. The issue is we like to use Ninject for all our projects. Stepping through the project's code that uses automapper is taking some time since our experience is very low with automapper. We ultimately would like to build a new MVC5 project, impliment Ninject, and copy/paste a lot of the code that uses automapper over to the new project which will use Ninject dependency injection.
Has anybody had a similar situation? Should we get more familiar with Automapper and consider not using Ninject for this new project? Any advice would be much appreciated.
Ok, after reading up more on Automapper, I think now I got a understanding of how it works. The way I normally populate my viewmodels are by doing the following:
public class Main
{
public int MainID { get; set; }
public string MainString { get; set; }
}
public class MainViewModel
{
public int Main { get; set; }
public string MainString { get; set; }
}
[HttpGet]
public ActionResult MainController()
{
MainViewModel model = new MainViewModel();
return View(model);
}
[HttpPost]
public ActionResult MainController(MainViewModel model)
{
if (ModelState.IsValid)
{
Main objMain = new Main();
objMain.MainString = model.MainString;
mainRepository.SubmitMain(objMain);
}
return View(model);
}
After looking at examples, I notice code such as:
MainViewModel model = Mapper.Map<Main, MainViewModel>(mainRepository.GetMain(id));
What is the overall benefit of Automapper? Is it just reduce lines of code?