0

I am using Automapper and StructureMap in my Web API application. I am getting the following error message during compilation. I have installed the following:

  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

    There is no implicit conversion from MapperConfiguration to IMapperConfiguration

at the following line of code:

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

The full code is below

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

        }
Community
  • 1
  • 1
Tom
  • 8,175
  • 41
  • 136
  • 267

1 Answers1

0

MapperConfiguration implements IConfigurationProvider only in Automapper 6.1.0.

Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114
  • So what is the solution to my problem. How would Create a mapper that will be used by the DI container and Register the DI interfaces with their implementation – Tom Jun 23 '17 at 10:45