Using AutoMapper with NInject in a non ASP.Net application

Using AutoMapper with NInject in a non ASP.Net application


In this blog post, I am going to show one of the several methods in which AutoMapper can be used with NInject IOC Container.

In ASP.Net / ASP.Net core, there are alternate ways. This is specifically for Console / Windows-based applications.


In the method where you would register the services such as the following code example:


kernel = new StandardKernel();

kernel.Bind<IService1>.To<Service1>();


In this method, you can bind AutoMapper, as in the following code sample:


var config = new MapperConfiguration((cfg) =>

{

    cfg.CreateMap<Entity1, Entity1BusinessObject>().ReverseMap();

    cfg.CreateMap<Entity2, Entity2BusinessObject>().ReverseMap();

});


var mapper = config.CreateMapper();

kernel.Bind<IMapper>().ToConstant(mapper)



Happy Developing!


Using AutoMapper with NInject in a non ASP.Net application

Comments

Popular posts from this blog

Multi-part Upload to S3 programmatically in .Net using C#

True Multi-Factor Authentication

How to install Kaldi-ASR on Ubuntu 18