2

I'm trying to use MVC Contrib Localization in my Asp.net MVC application, for now I have it working with resource files, but I want to use it with Sql Server,

I'm checking this tutorial: http://www.codeproject.com/Articles/352583/Localization-in-ASP-NET-MVC-with-Griffin-MvcContri

but it uses Autofac as the IoC container which I don't understand, does anyone have used it with Ninject? or anyone knows how this Autofac code can be transated to 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();

Thanks in advance.

jgauffin
  • 99,844
  • 45
  • 235
  • 372
Escobar5
  • 3,941
  • 8
  • 39
  • 62

1 Answers1

0

I am trying to do the same thing at the moment with the Ninject.Web.MVC NuGet package.

I am not sure if Ninject has anything similar to .AsImplementedInterfaces() however you can still bind the interfaces yourself if not, its just more manual work looking at Griffin.MvcContrib's classes and what interfaces they implement.

One example to put in the NinjectWebCommon RegisterServices method is:

private static void RegisterServices(IKernel kernel)
{
    kernel.Bind<ILocalizedStringProvider>()
           .To<RepositoryStringProvider>().InRequestScope();
...
}  

The InRequestScope extension (https://github.com/ninject/Ninject.Web.Common/wiki/Inrequestscope), from what I have read so far, is the closest I can see to the AutoFac .InstancePerLifetimeScope() http://code.google.com/p/autofac/wiki/InstanceScope

As for .RegisterInstance(new AdoNetConnectionFactory("DemoDb")).AsSelf();

There is a .ToSelf() method for Ninject but I am not entirely sure what this line is doing yet myself.

Pricey
  • 5,799
  • 12
  • 60
  • 84