Prismatic modules and databases

I'm busy studying Prism 4 and everyone else, but I still have to see the tutorial / go through what I want to complete. Hope someone here worked or worked on a similar project.

My application is the main CRUD application, which I have divided into separate areas of concern, and therefore modules. However, I want all the modules to share one common SQL Express local database. The database will start with a limited number of tables to start with it, and each module will check the database for the tables it needs, and if they are not there, create them. How can i do this?

I was thinking of just adding to all my tables initially, but this seems to violate the principle of modularity in my mind. My thinking may be wrong, but what will be the point of loosely coupled modules if the database is already fully aware and strongly connected with this module from creating db?

We are looking for some kind of understanding.

+3
source share
3 answers

You seem to be asking two questions. First: How can I use PRISM to make sure my modular concrete schema exists in the database, and if not, create one. The second question: how can I better structure my data layer so that it is shared in a modular application.

, , :

, , , . , . Prism, Id, , : (MyPlugInModule.cs) , Microsoft.Practices.Prism.Modularity.IModule. Initialize, , , . , .

, , :

, , . , , , , .

Entity Framework, . , , , / , . .

, , WPF MVVM, PRISM MEF WCF. , , ( /, ..). , , , .

, , , , . , .. , , .

, . PRISM 4 MEF, 4, , .

+3

- ? - - . .

- - ( ), .. ..

5 :)

+2

, , , . , , .

, , . . Entity Framework, , "" -.

Bootstrapper.cs:

....
protected override void ConfigureContainer() {
    base.ConfigureContainer();
    // Register my navigation
    Container.RegisterType<IAppDatabaseContext, AppDatabaseContext>();
}
....

AppDatabaseContext.cs:

public class AppDatabaseContext : DbContext, IAppDatabaseContext {
    DbSet<MyModelOne> MyModelOnes { get; set; }
    DbSet<MyModelTwo> MyModelTwos { get; set; }
    DbSet<MyModelThree> MyModelThrees { get; set; }
}

public interface IAppDatabaseContext {
    DbSet<MyModelOne> MyModelOnes { get; set; }
    DbSet<MyModelTwo> MyModelTwos { get; set; }
    DbSet<MyModelThree> MyModelThrees { get; set; }

    int SaveChanges();
    // Other methods needed to use the DbContext
}

ViewModels:

public ConstructorMethod(IEventAggregator eventAggregator, IAppDatabaseContext dbContext) {
    _db = dbContext; // I then use this in my Observed Properties
}
0
source

Source: https://habr.com/ru/post/1775094/


All Articles