Skip to content

A template for an API using Clean Architecture and .NET Minimal API's.

License

Notifications You must be signed in to change notification settings

akshatcdec/CleanMinimalApi

Repository files navigation

Clean Minimal API

GitHub Workflow Status Codecov Nuget

This is a template API using Clean Architecture alongside .net 6's Minimal APIs.

Prerequisites

This solution in built on the .net 6 SDK, you need to install that before it will work for you. If you want to build the Dockerfile you will need to install Docker as well.

Installation

This is a template and you can install it using the dotnet new cli. To install the lastest version of the template run the following command.

dotnet new --install CleanMinimalApi.Template

To create a new solution using this template run the following command

dotnet new cleanminimalapi --name {YOUR_SOLUTION_NAMESPACE} --au "{YOU_AUTHORS_NAME}"

Docker

There's a dockerfile included in the build folder and serves the purpose of restoring, building, testing, publishing and then creating a runtime image of the API. Works on my machine.....you can add a version prefix and suffix to version the service in the assembly. The Dockerfile does have stages so you can just run the tests or publish the solution depending on your needs. Review the build-pipeline.yml in the github folder for more detailed usage.

docker build . -t cleanminimalapi:latest --build-arg VERSION_PREFIX {VERSION_NUMBER} -- build-arg VERSION_SUFFIX {PRERELEASE_NAME}

The Github Action does publish an image of this API and you check it out for yourself by runnning this command in docker.

docker pull stphnwlsh/cleanminimalapi

Architecture

This solution is loosly based on Clean Architecture patterns, it's by no means perfect. I prefer to call it "Minimal Clean Architecture". Much inspiration has been taken from Jason Taylor's Clean Architecture Template, but I have takend some things further and scaled back others.

  1. As with Jason's solution the Infrastructure project is referenced by the Presentation project. This is for Dependency Injection purposes, so to protect this a little further, all classes in the Infrastructure project are internal. This stops them being accidentally used in the Presentation project.
  2. There's no Automapper, it's a great library but there's no need for it here. The domain is simple and so save effor, heartache and pain I am not mapping anything. The Domain models run through the project, this is why I call this clean-ish architecture.

Features

There are plenty of handy implementations of features throughout this solution, in no particular order here are some that might interest you.

Resources

This sample would not have been possible without gaining inspiration from the following resources. If you are on your own learning adventure please read the following blogs and documentation.

Support

I'm sharing some of my work here and if it helps you, I'd love it if you'd consider supporting me.

"Buy Me A Coffee"

About

A template for an API using Clean Architecture and .NET Minimal API's.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 98.8%
  • Dockerfile 1.2%