Hi Keith,I think this is along the lines of what you want:builder.Register(c => Mapper.Engine).As<IMappingEngine>();
builder.Register<TypeMapFactory>().As<ITypeMapFactory>();builder.Register(c => AutoMapper.Mappers.MapperRegistry.AllMappers());
builder.Register<AutoMapper.Configuration>().As<AutoMapper.Configuration>().As<IConfigurationProvider>().As<IConfiguration>();The invocation of AllMappers() is registered as type IEnumerable<IObjectMapper>, which allows the constructor of Configuration to be autowired.I've never used AutoMapper myself, so I'm cross-posting to AutoMapper Users in the hope that someone there can validate this :)Cheers,
Nick2009/9/17 Keith <krou...@gmail.com>
Hi,
I am trying to configure AutoMapper with Autofac and am running into
an error. Basically, it is telling me that I have no resolvable
constructors for Configuration.
Here is what I am trying to do:
builder.Register(c => Mapper.Engine).As<IMappingEngine>();
builder.Register<TypeMapFactory>().As<ITypeMapFactory>();
builder.Register<AutoMapper.Configuration>(c => new
AutoMapper.Configuration(c.Resolve<ITypeMapFactory>(),
AutoMapper.Mappers.MapperRegistry.AllMappers.Invoke()))
.As<AutoMapper.Configuration>().SingletonScoped();
builder.Register<AutoMapper.Configuration>
().As<IConfigurationProvider>();
builder.Register<AutoMapper.Configuration>
().As<IConfiguration>();
In the code above, AutoMapper.Mappers.MapperRegistry.AllMappers is
Func<IEnumerable<IObjectMapper>>
There is an example of this using StructureMap here:
http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/05/11/automapper-and-ioc.aspx
The line that I am struggling to recreate is this:
ForRequestedType<Configuration>()
.CacheBy(InstanceScope.Singleton)
.TheDefault.Is.OfConcreteType<Configuration>()
.CtorDependency<IEnumerable<IObjectMapper>>().Is(expr =>
expr.ConstructedBy(MapperRegistry.AllMappers));
Is there anything equivalent to CtorDependency or is there another way
to construct a statement that will do something similar?