Flexbase Solution Structure

The next infrastructure layer we look at is the Persistence layer.

Persistence takes care of the data persistence in the database. Let us look at the default configurations.

For Persistence, by default, we have configured to Entityframework.

The first project that comes under persistence is BaseEF. Here we have a ApplicationEFDBContext. This inherits from FlexEFDbcontext and that in turn implements the Entityframework DBcontext.

The second one is the ApplicationTenantEFDbContext. We will learn more details about the tenant providers when we come across the topic on developing multitenant applications.

Next thing that we need is the connection settings with ConnectionProvider. We have set up two default connection providers. First is AppSettingsReadDBConnectionProvider and another one is the AppSettingWriteDBConnectionProvider.

We are separating one connection for ReadDB and another one connection for WriteDB.

All the operations that happen in the Handler mostly will be the Write DB and all the operations that are happening in the queries will be the Read DB. But if a single DB is needed for both, one can keep the same connection string for the both the settings.

This reads the settings as shown here.

FlexBase AppReadDbConnection for the read connection provider and AppDbConnection for the write connection provider. It can be changed by overriding the properties in respective ConnectionProvider.

We also have NativeReadDbTenantConnectionProvider . We will learn about the tenancy in multi-tenant application section.

Then we have the BaseEF.SQLServer. This initializes the connection to use SQL server and it uses the connection provider’s connection string.

We have done the same thing for BaseEF.MySQL, but by default, we have all the SQL Server configuration configured in DI in the startup code.

We also have the migrations project created for you

Migration uses the ApplicationEFDbMigrationContext. This is a new context here that inherits from the ApplicationEFDbContext from BaseEF.

If you need any model overriding or any indexing or the model customization you can do it in ApplicationEFDbContext in BaseEF.

Note: But you don't need to add any of your entities inherited from DomainModelBridge to the ApplicationEFDbContextbecause Flex will add all your entities to the model builder automatically.

Unless some specific customization is needed, you don't need any code to be added to the ApplicationEFDbContext.

We will get into those details when we learn more about insert update and all the Crud operations.

We have the migrations for SQLTenantDB separately also, which we will cover in the multi-tenant application section.

Last updated