.Net Core API - Repository pattern with auto refresh cache. This is a simple API using the repository design pattern to get data from a database. The data from the database are being cached either InMemory or in Redis(for scaled systems).
Clone the repo, open a terminal and run make
to see all the possible actions.
The project setup is based on Domain Driven Design:
GNU Make
.Net Core v5.0
Docker
- Your favorite IDE/editor
I created a makefile to make it as easy as possible to get the docker containers up and runnig 😎. The only thing you need to do is run:
make up
After that you need to wait for the project to build and you are all set!
The make command will run the docker-compose file and download all the images required for the porject. This will take some time so be patient ☕.
When the make up
command is finished, you should have 3 containers running:
- The web API @: http://localhost:8000/
- A SQL server with some dummy data already seeded in a database.
- A redis cache which is being used when you set redis as the cache provider.
Alternatively, you can run the RepositoryWithCaching.WebApi
project which will use In-memory(by default) data instead of a database on a sql server.
- .Net Core v5.0
- AutoMapper - A convention-based objet-objet mapper.
- Hangfire - Easy and reliable library to perform fire-and-forget tasks.
- MediatR - Simple mediator implementation in .NET.
- Swagger - Tools for documenting APIs.
A good read on distributed caching for .Net Core: Distributed caching in ASP.NET Core.
- George Garyfallou - Initial work - gegaryfa
- Hat tip to anyone whose code was used