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:
StructureMap 4.5
StructureMap.MVC5 3.1.1.134
StructureMap.web 4.0.0.315
StructureMap.webapi2 3.0.4.125
There is no implicit conversion from
MapperConfiguration
toIMapperConfiguration
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>();
}