Configuring DbContext¶
The EFCore module will read values from IConfiguration
and populate the
DbContextOptions<TDbContext>
for you. This is what provides the connection
string, database provider to use, etc.
The configuration may be applied by default, to all DbContext
s and/or you may
configure each one of them manually.
Most our services will have a single DbContext
, however some Suite Modules you
import may require its own persistence, hence configuring the defaults instead
of each context is recommended.
Default Configuration¶
The most common way to provide configuration is using the appsettings.json
file, however since the values come from IConfiguration
any source may be
used.
JSON | |
---|---|
Configuring a ProviderKey
is a requirement for the EFCore module to know which
Database Provider to use.
The list of valid providers can be found on the
ITsynch.Suite.Persistence.DatabaseProvider
class. Currently it contains the
following providers:
SqlServer
Sqlite
Oracle
(Not implemented yet)
Per DbContext Configuration¶
Each DbContext
can be configured manually as well by using the
ContextOptions
:
JSON | |
---|---|
The ContextOptions
is a Dictionary of DbContext
class name to its options.
Important
ContextOptions overrides the Default Options provided at the EFCore module level.