1
votes

There's one thing I could't handle in implementing Bounded context with Entity Framework :

Having the entities (even their properties) distributed in multiple contexts , I feel the need to centralize the whole model in a specific area, that would be responsible for managing migrations.

Am I on the right track ? Am I missing an important piece of the implementation puzzle?

1

1 Answers

1
votes

You are right, I used multiple DbContext In my project too, I defined each mudule's DbContext In following format:

public class Module1Context : DbContext 
{ 
     public Moduled1Context() 
        : base("MyDatabase") //<=== I passed this ConnectionString parameter 
                             //     to all modules
     { 
     } 
     ...
}

public class Moduled2Context : DbContext 
{ 
     public Moduled2Context() 
        : base("MyDatabase") 
     { 
     } 
     ...
}

And then defined a main DbContext that contains all DbSets from all module's DbContexts and use it for managing Migrations:

public class AllModulesContext : DbContext 
{ 
     public AllModulesContext() 
        : base("MyDatabase") 

     { 
     } 
     //dbSets from all modules
     ...
}