Injecting AutoMapper dependencies using Ninject

后端 未结 3 1988
我寻月下人不归
我寻月下人不归 2021-02-08 10:37

I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard\'s post on AutoMapper and StructureMap type Configuration as a guid

3条回答
  •  我在风中等你
    2021-02-08 11:31

    It might also be a good idea to introduce a mapping facade. Instead of passing IMappingEngine through out your code create an IObjectMapper interface. The interface I use contains method signatures taken directly out of automappers code.

    public interface IObjectMapper
    { 
      TDestination Map(TSource source);
      TDestination Map(TSource source, TDestination destination);
      object Map(object source, Type sourceType, Type destinationType);
      object Map(object source, object destination, Type sourceType, Type destinationType);
    }
    

    Your configuration is still going to be automapper dependent.

    A blog post I wrote on it is here: http://fodonnel.wordpress.com/2010/09/20/an-object-mapper-facade/

提交回复
热议问题