我正在尝试在我的Sql应用程序中使用MVC本地化,目前我已经将其用于资源文件,但我想将其用于Asp.net Server。
我正在查看这个教程:http://www.codeproject.com/Articles/352583/Localization-in-ASP-NET-MVC-with-Griffin-MvcContri
但是它使用Autofac作为IoC容器,我不明白,有没有人用过它?或者任何人都知道如何将此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();提前谢谢。
发布于 2012-12-24 10:48:20
我现在也在尝试用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()方法,但我自己还不完全确定这行代码在做什么。
https://stackoverflow.com/questions/12957969
复制相似问题