【问题标题】:There is no implicit conversion from MapperConfiguration to IMapperConfiguration没有从 MapperConfiguration 到 IMapperConfiguration 的隐式转换
【发布时间】:2017-06-21 06:35:01
【问题描述】:

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

  1. 结构图 4.5

  2. 结构图.MVC5 3.1.1.134

  3. StructureMap.web 4.0.0.315

  4. StructureMap.webapi2 3.0.4.125

    没有从MapperConfigurationIMapperConfiguration 的隐式转换

在以下代码行:

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>();

        }

【问题讨论】:

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


    【解决方案1】:

    MapperConfiguration implements IConfigurationProvider 仅在 Automapper 6.1.0 中。

    【讨论】:

    • 那么我的问题的解决方案是什么。如何创建一个将由 DI 容器使用的映射器并将 DI 接口注册到它们的实现中
    猜你喜欢
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多