Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 没有从MapperConfiguration到IMapperConfiguration的隐式转换_C#_Asp.net Mvc_Automapper_Structuremap_Structuremap4 - Fatal编程技术网

C# 没有从MapperConfiguration到IMapperConfiguration的隐式转换

C# 没有从MapperConfiguration到IMapperConfiguration的隐式转换,c#,asp.net-mvc,automapper,structuremap,structuremap4,C#,Asp.net Mvc,Automapper,Structuremap,Structuremap4,我在Web API应用程序中使用Automapper和StructureMap。 我在编译期间收到以下错误消息。我已安装以下设备: 结构图4.5 StructureMap.MVC5 3.1.1.134 StructureMap.web 4.0.0.315 StructureMap.webapi2 3.0.4.125 没有从MapperConfiguration到IMapperConfiguration 在以下代码行: For<IMapperConfiguration>().U

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

  • 结构图4.5

  • StructureMap.MVC5 3.1.1.134

  • StructureMap.web 4.0.0.315

  • StructureMap.webapi2 3.0.4.125

    没有从
    MapperConfiguration
    IMapperConfiguration

  • 在以下代码行:

    For<IMapperConfiguration>().Use(config);
    
    For()。使用(配置);
    
    完整代码如下

    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>();
    
            }
    
    public类DefaultRegistry:Registry
    {
    #区域构造函数和析构函数
    公共注册处()
    {
    var profiles=来自typeof(DefaultRegistry.Assembly.GetTypes()中的t
    其中typeof(Profile).IsAssignableFrom(t)
    选择(Profile)Activator.CreateInstance(t);
    var config=new-MapperConfiguration(cfg=>
    {
    foreach(配置文件中的var配置文件)
    {
    cfg.AddProfile(profile);
    }
    });
    //创建DI容器将使用的映射器
    var mapper=config.CreateMapper();
    //注册DI接口及其实现
    For()。使用(config);
    For()。使用(映射器);
    //注册UserRepository并将映射器的实例传递给其构造函数
    For().Use().Ctor().Is(映射器);
    For().Use();
    For().Use();
    For().Use();
    For().Use();
    For().Use();
    }
    
    MapperConfiguration
    IConfigurationProvider
    仅在Automapper 6.1.0中提供。

    那么我的问题的解决方案是什么。如何创建一个映射器,供DI容器使用,并在实现中注册DI接口