External¶
External data seeding can be seen as DataGathering counterpart: while data gathering feature aims to retrieve required data from another service, external data seeding is responsible for seeding data from one service to another, while ensuring this process is completed in a resilient way.
Yet, there's quite a few things that must be configured from the module's API. First and foremost, a DbContext
must be specified so the module can register the required type configurations.
C# | |
---|---|
One thing to notice is this module (and particularly the external seeding feature) is commonly used by client modules, which do not have a DbContext
type specified by themselves. For these cases, an IConfigureOptions
works as a safe pattern for chaining the DbContext
type.
This allows the DataSeeding module to inherit the DbContext
type that is set to your client module.
Additionally, a version is required to be specified. The recommended approach here is to define it from your application's appsettings.json
file as follows:
JSON | |
---|---|
Note
Versioning is still an experimental feature, which aims to behave similar as EF Core migrations versioning work. You will find out we're not quite there yet, but this is a good start.
Now lets move forward. The module's API can be used as follows:
Lets break this down:
T
is the type being attempted to seed from the client's perspective. Usually a DTO containing the data that should be mapped to a message.TMessage
is the message to be used for creating the required entities.TResponse
is the response message we expect if using the default Request/Response seeding strategy.TDataSource
is theIDataSource
implementation that holds the data to be seeded. DataSources are described here.
The method receives two arguments:
- A correlationId selector lambda expression
- A value indicating whether to contribute with health-checks (see below).
Important
An AutoMapper profile from T
to TMessage
is required for the module to properly map the DTO to the message type. No further configuration is required but to define the profile, which will be auto-discovered.
Note
As stated, the default seeding strategy uses request/response. A future version of this module will allow to override this behavior to use your own custom implementation.
Note
It is suggested, yet not required, to use special "create if not exist" messages here, so an eventual service restart will not override changes made by the users to the seeded data.
HealthChecks¶
External DataSeeding
is capable to contribute to health checks. By default, every type exposed for data seeding through the module's API will be included in this validation.