First, create a MapperConfiguration and from it an IMapper , for which all your types are configured as follows:
var config = new MapperConfiguration(cfg => {
Then register the mapper instance with the unity container as follows:
container.RegisterInstance(mapper);
Then, any controller (or service) that wants to use the converter can declare such a dependency in the constructor as follows:
public class MyHappyController { private readonly IMapper mapper; public MyHappyController(IMapper mapper) { this.mapper = mapper; }
Assuming you configured the MVC framework properly, the controller should be constructive without any problems.
source share