A project template that I use to quickly create a set of repository classes for interacting with any existing database.
- The DbContext class is internal, which means that external libraries users cannot make db changes without interacting with the repository classes.
- The repository classes validate the entities before making changes to the database keeping it clean.
- A Result type is returned in case of success or failure, instead of relying on exceptions. Makes testing and validation easier.
- A notification is published for every Create, Update and Delete event. External libraries can subscribe to these events and accordingly perform any required action.
csxtemplates to customize the entities,the repository classes and the model classes that are output by the generator.- Integration tests using TestContainers helps testing the repository classes with a real database that is spun up and down as the tests execute.
First, initialize the submodules using git submodule update --init.
Build the solution - Platy.AdventureWorks.Repository.sln.
Open the solution - EntityFrameworkCore.Generator/EntityFrameworkCore.Generator.sln and build it.
This is one of the submodules downloaded.
Execute the command ..\..\efg\EntityFrameworkCore.Generator.exe generate -f .\entity-generation.yml from the directory of Platy.AdventureWorks.Repository.csproj.
This generates the domain files. Make sure the AdventureWorks database is available.