首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Ninject中使用griffin.mvccontrib.localization

如何在Ninject中使用griffin.mvccontrib.localization
EN

Stack Overflow用户
提问于 2012-10-18 23:15:49
回答 1查看 565关注 0票数 2

我正在尝试在我的Sql应用程序中使用MVC本地化,目前我已经将其用于资源文件,但我想将其用于Asp.net Server。

我正在查看这个教程:http://www.codeproject.com/Articles/352583/Localization-in-ASP-NET-MVC-with-Griffin-MvcContri

但是它使用Autofac作为IoC容器,我不明白,有没有人用过它?或者任何人都知道如何将此Autofac代码转换为Ninject:

代码语言:javascript
复制
// 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();

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-12-24 10:48:20

我现在也在尝试用Ninject.Web.MVC NuGet包做同样的事情。

我不确定Ninject是否有类似于.AsImplementedInterfaces()的东西,但是如果没有,你仍然可以自己绑定接口,这只是查看Griffin.MvcContrib的类和它们实现的接口的更多手动工作。

放在NinjectWebCommon RegisterServices方法中的一个例子是:

代码语言:javascript
复制
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()方法,但我自己还不完全确定这行代码在做什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12957969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档