没有从MapperConfiguration到IMapperConfiguration的隐式转换

时间:2017-06-21 06:35:02

标签: c# asp.net-mvc automapper structuremap structuremap4

我在Web API应用程序中使用Automapper和StructureMap。 我在编译期间收到以下错误消息。我安装了以下内容:

  1. StructureMap 4.5
  2. StructureMap.MVC5 3.1.1.134
  3. StructureMap.web 4.0.0.315
  4. StructureMap.webapi2 3.0.4.125

      

    没有从MapperConfigurationIMapperConfiguration

    的隐式转换
  5. 在以下代码行中:

    For<IMapperConfiguration>().Use(config);
    

    完整代码位于

    之下
    public class DefaultRegistry : Registry
        {
            #region Constructors and Destructors
    
            public DefaultRegistry()
            {
                var profiles = from t in typeof(DefaultRegistry).Assembly.GetTypes()
                               where typeof(Profile).IsAssignableFrom(t)
                               select (Profile) Activator.CreateInstance(t);
    
    
                var config = new MapperConfiguration(cfg =>
                {
                    foreach (var profile in profiles)
                    {
                        cfg.AddProfile(profile);
                    }
                });
    
    
    
                //Create a mapper that will be used by the DI container
                var mapper = config.CreateMapper();
    
                //Register the DI interfaces with their implementation
                For<IMapperConfiguration>().Use(config);
                For<IMapper>().Use(mapper);
    
    
                //Register the UserRepository and pass instance of Mapper to its constructor
                For<IMovieBusiness>().Use<MovieBusiness>().Ctor<IMapper>().Is(mapper);
    
                For<IConnectionFactory>().Use<ConnectionFactory>();
                For<IMovieRepository>().Use<MovieRepository>();
                For<IUnitOfWork>().Use<UnitOfWork>();
                For<IMovieService>().Use<MovieService>();
                For<IMovieBusiness>().Use<MovieBusiness>();
    
            }
    

1 个答案:

答案 0 :(得分:0)

仅在Automapper 6.1.0中

MapperConfiguration implements IConfigurationProvider