c# - Use namespace to distinguish between two IUnitOfWork implementation -


I'm developing C #, .NET Framework 4.0 with an ASP.NET MVC 4 mesh API, the unit code code first 6.0 and Nunzek

I would like to have two separate DbContext custom assignments because I have to connect to two separate databases.

This is my custom DbContext class implementation

  public class EFDbContext:. DbContext, IUnitOfWork {public EFDbContext (): base ("name = EFDbContext") {// Exit, then there is no database, do not create database.SetInitializer & LT; EFDbContext & gt; (Zero); } Protected Override Zero OnModelCreating (DbModelBuilder modelBuilder) {modelBuilder.Configurations.Add (new CONFIGURATIONSConfiguration ()); Modlbilder Configuration. Add (new code configuration ()); Modlbilder Configuration. Add (new AGGREGATION_CHILDS configuration ()); Modlbilder Configuration. Add (new AGGREGATIONSConfiguration ()); Base.OnModelCreating (modelBuilder); }}   

Both DbContext custom classes IUnitOfWork and my problem is that if I get from them how do I distinguish between them Do not know how to do NinjectConfigurator class:

  Private Zero AddBindings (IKernel Container) {ConfigureLog4net (Container); Container.Bind & LT; IUnitOfWork & gt; () & Lt; EFDbContext & gt; () InRequestScope (); // hidden implementation ...}   

If I have two different EFDbContext classes, how can I distinguish them from NinjectConfigurator

Maybe I can use the same IUnitOfWork interface with two different namespaces and I can use the namespace to differentiate between them. The problem here is that I will repeat the same interface in two different names spaces.

You should name them

  bind & Lt; IUnitOfWork & gt; () & Lt ;. EFDbContext & gt; () Name ("ef"); Bind & lt; IUnitOfWork & gt; () & Lt; OtherDbContext & gt; () Name ("other");   

Allows you to do this:

  class MyRepository {Personal IUnitOfWork _unitOfWork; Public ([Named ("EF")] IUnitOfWork unitOfWork) _unitOfWork = unitOfWork; }}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -