KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers); Bind<IConfiguration>().To<Configuration>(); Bind<IConfigurationProvider>().To<Configuration>(); Bind<IMappingEngine>().To<MappingEngine>(); } } Ninject throws an exception when resolving Configuration . Error activating IObjectMapper No matching bindings are available, and the type is not self-bindable. Activation path: 3) Injection of dependency IObjectMapper into parameter mappers of constructor of type Configuration Update This is now working using the following binding: Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToConstant(new Configuration(Kernel.Get<ITypeMapFactory>(), MapperRegistry.AllMappers())).InSingletonScope(); Bind<IConfiguration>().ToMethod(c => c.Kernel.Get<Configuration>()); Bind<IConfigurationProvider>().ToMethod(c => c.Kernel.Get<Configuration>()); Bind<IMappingEngine>().To<MappingEngine>(); I published the module on GitHub. AutoMapper.Ninject . More information on my blog: http://binaryspeakea
Tags (comma-separated)
Save Edits
Cancel