使用Ninject将AutoMapper注入ASP.NET MVC 2应用程序时遇到麻烦.我用Jimmy Bogard的帖子在
AutoMapper and StructureMap type Configuration作为指导.
原文链接:/javaschema/281418.htmlpublic 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抛出异常.@H_403_4@
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@H_403_4@
更新@H_403_4@
现在正在使用以下绑定:@H_403_4@
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>();
我在GitHub上发布了这个模块. AutoMapper.Ninject.有关我的博客的更多信息:http://binaryspeakeasy.com/2010/09/automapper-ninject/@H_403_4@