I have a multitenant web application which has multiple modules. I am using autofac as IOC and Automapper to map my model and entities. In the following code I am able to add UserAuthenticationMapper profile to the automapper, but unable to add CustomerDataMapper profile. Autofac is adding just one mapper profile to the automapper MappingEngine and ignoring rest of it. Whats wrong I am doing here?
Here's my UserAuthentication Module:
public class UserAuthenticationModule: Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<MappingEngine>().As<IMappingEngine>();
builder.Register(ctx =>
{
var configStore = new ConfigurationStore
(new TypeMapFactory(), MapperRegistry.AllMappers());
configStore.AddProfile<UserAuthenticationMapperProfile>();
return configStore;
})
.AsImplementedInterfaces()
.SingleInstance();
var assembly = Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(assembly)
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces()
.SingleInstance();
}
}
CustomerData Modue:
public class CustomerDataModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<CustomerDataService>()
.As<ICustomerDataService>()
.InstancePerDependency();
builder.RegisterType<MappingEngine>().As<IMappingEngine>();
builder.Register(ctx =>
{
var configStore = new ConfigurationStore
(new TypeMapFactory(), MapperRegistry.AllMappers());
configStore.AddProfile<CustomerDataMapperProfile>();
return configStore;
})
.AsImplementedInterfaces()
.SingleInstance();
}
}
here is some additional code to show how i am loading these modules in Global.asax
static IContainerProvider _containerProvider;
public IContainerProvider ContainerProvider
{
get { return _containerProvider; }
}
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}"
);
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
var builder = new ContainerBuilder();
builder.RegisterModule<UserAuthenticationModule>();
builder.RegisterModule<CustomerDataModule>();
_containerProvider = new ContainerProvider(builder.Build());
}
Error:
An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code Missing type map configuration or unsupported mapping.\r\n\r\nMapping types:\r\nUser -> UserModel