我正在尝试在我的Asp.net MVC应用程序中使用MVC Contrib Localization,现在我让它使用资源文件,但我想将它与Sql Server一起使用,
我正在查看本教程:http://www.codeproject.com/Articles/352583/Localization-in-ASP-NET-MVC-with-Griffin-MvcContri
但它使用Autofac作为IoC容器,我不明白,是否有人将它与Ninject一起使用?或者任何人都知道如何将这个Autofac代码转换为Ninject:
// Loads strings from repositories.
builder.RegisterType<RepositoryStringProvider>().AsImplementedInterfaces().InstancePerLifetimeScope();
builder.RegisterType<ViewLocalizer>().AsImplementedInterfaces().InstancePerLifetimeScope();
// Connection factory used by the SQL providers.
builder.RegisterInstance(new AdoNetConnectionFactory("DemoDb")).AsSelf();
builder.RegisterType<LocalizationDbContext>().AsImplementedInterfaces().InstancePerLifetimeScope();
// and the repositories
builder.RegisterType<SqlLocalizedTypesRepository>().AsImplementedInterfaces().InstancePerLifetimeScope();
builder.RegisterType<SqlLocalizedViewsRepository>().AsImplementedInterfaces().InstancePerLifetimeScope();
提前致谢。
答案 0 :(得分:0)
我正在尝试使用Ninject.Web.MVC NuGet包做同样的事情。
我不确定Ninject是否有类似.AsImplementedInterfaces()
的内容,但是如果没有,你仍然可以自己绑定接口,它只是更多的手工工作,查看Griffin.MvcContrib的类以及它们实现的接口。
放入NinjectWebCommon RegisterServices方法的一个例子是:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<ILocalizedStringProvider>()
.To<RepositoryStringProvider>().InRequestScope();
...
}
到目前为止,InRequestScope
扩展程序(https://github.com/ninject/Ninject.Web.Common/wiki/Inrequestscope)是我能看到的最接近AutoFac的.InstancePerLifetimeScope()
http://code.google.com/p/autofac/wiki/InstanceScope
至于.RegisterInstance(new AdoNetConnectionFactory("DemoDb")).AsSelf();
Ninject有一个.ToSelf()
方法,但我自己并不完全确定这条线是做什么的。