Client module¶
The Spares service provides a Client Module for other services that need to integrate with Spare, can do it easily.
The SparesClientModule
provides a materialized representation of a Spare, the
SpareMetaData
. Also, it brings to the table an internal API that maintains up
to date the Spare Metadata with the changes made on the Spares Service.
Currently, the SpareMetaData
includes:
- Spare correlation id.
- Spare display name.
- Spare code.
- Maker display name.
- Maker reference.
- Spare price.
- In stock quantity.
- Unit of Measure.
How to use it¶
The main idea behind the SparesClientModule
is that, when you create your own
entity (i.e Component
), you can add relations to SpareMetaData
, which is
provided by the module.
The DB structure is included as your own service's migrations, and it is handled as another regular entity. The only difference is that we can share the class and it's mapping so that you don't need to write them.
Defining an Entity with a SpareMetaData¶
First we need to reference the SparesClientModule
's Abstraction assembly from
our Domain layer.
XML | |
---|---|
This will allow us to create an entity which has a Spare
:
C# | |
---|---|
We then need to add an EntityTypeConfiguration for this entity on our Persistence layer as usual:
After doing that, we must reference and configure the SparesClientModule
on
our Application Module before we can generate migrations.
Configuring the Application Module¶
First, we need to reference the SparesClientModule
's assembly from in our
Application layer project:
XML | |
---|---|
Then we need to depend on the SparesClientModule
and also configure the
DbContext where we want the Spare Metadata entity added to. This is usually the
only DbContext that you have, which is the one generated by the microservice
template:
C# | |
---|---|
This is all that you need in order for the module to register the
EntityTypeConfiguration
for SpareMetaData against the DbContext you've just
specified.
We can now generate migrations for our service as usual, and we should see the one to one relation we just added, and the table for SpareMetaData being created.