一个使用清洁架构和 .NET 简洁 API 的 API 模板。
This is a template API using a streamlined version of Clean Architecture alongside .NET's Minimal APIs.
This solution in built on the .NET 10 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.
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.TemplateTo create a new solution using this template run the following command
dotnet new cleanminimalapi --name {YOUR_SOLUTION_NAMESPACE} --au "{YOU_AUTHORS_NAME}"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/cleanminimalapiThis solution is loosely based on Clean Architecture patterns, it's by no means perfect. I prefer to call it "Lean Mean Clean Architecture". Inspiration has been taken from Jason Taylor's Clean Architecture Template, but I have made some structural decisions to take some things further and scaled back others.
There's a little CQRS type stuff going on here but it's more in style than real separated functions for reading and writing as under the covers they are the same data source.
Breaking the Clean Architecture pattern is the fact that 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.
It's streamlined into 3 functional projects. All serve their own purpose and segregate aspects of the application to allow easier replacement and updating.
There are plenty of handy implementations of features throughout this solution, in no particular order here are some that might interest you.
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.
If you like this, or want to checkout my other work, please connect with me on LinkedIn, and/or follow me on Medium or GitHub.
If you want to see more updates or more projects then please support me at GitHub Sponsors or Buy Me A Coffee
暂无开放 Issues,或尚未同步最近议题。