Pregunta

He usado NINECT para mi solicitud.NINTECT es realmente simple y fácil de aprender, pero es bastante lento e intento usar otra COI para comparar si es más rápido que con NINJECT.

Hay muchos contenedores de IOC para MVC3 y el simple inyector se ve muy bueno conmigo, pero tengo muchos problemas con la replacción de ninjecos con inyector simple .

Especialmente con el AutoMapper.Intento convertir estas líneas en un código de inyector simple.

Bind<ITypeMapFactory>().To<TypeMapFactory>();

foreach (var mapper in MapperRegistry.AllMappers())
{
    Bind<IObjectMapper>().ToConstant(mapper);
}

Bind<ConfigurationStore>().ToSelf().InSingletonScope()
    .WithConstructorArgument("mappers",
        ctx => ctx.Kernel.GetAll<IObjectMapper>());

Bind<IConfiguration>()
    .ToMethod(ctx => ctx.Kernel.Get<ConfigurationStore>());

Bind<IConfigurationProvider>().ToMethod(ctx =>
    ctx.Kernel.Get<ConfigurationStore>());

Bind<IMappingEngine>().To<MappingEngine>()

¿Puedes ayudarme?He leído la documentación y el googled, pero no hay solución hasta ahora.

¿Fue útil?

Solución

Este registro de niRescribir aproximadamente se traduce en el siguiente registro de inyector simple:

container.Register<ITypeMapFactory, TypeMapFactory>();
container.RegisterCollection<IObjectMapper>(MapperRegistry.AllMappers());
container.RegisterSingleton<IConfiguration, ConfigurationStore>();
container.RegisterSingleton<IConfigurationProvider, ConfigurationStore>();
container.Register<IMappingEngine, MappingEngine>();

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top