Clear Structure Answer Template




I’ve develop into an enormous fan of the Clear Structure sample when engaged on .NET API’s. I gained’t go right into a ton of element right here, as there are a number of nice assets on the market on the topic already, together with from the person who I first realized it from, Jason Taylor. Should you’re unfamiliar with this sample, do your self a favor and take a look at this presentation by Jason from the GOTO 2019 convention:

However on the 10,000 foot stage, an API mission utilizing the Clear Structure sample has 4 separate initiatives (together with the mandatory unit testing initiatives):

  • Area – This mission is supposed to carry the area entities of the appliance. The lessons on this mission map to the info tables or data in no matter knowledge retailer the appliance is configured to make use of.
  • Utility – This mission comprises the enterprise logic and guidelines that make the appliance as a complete run because it’s purported to. It straight references the Area mission, however no different initiatives throughout the answer.
  • Infrastructure – This mission comprises the implementation of any logic that should talk with exterior entities, akin to a database, the file system, different HTTP API’s, and so forth. It references the Utility mission to achieve entry to software contracts that it’s going to then implement for accessing the aforementioned exterior entities.
  • Api – That is the front-end of the appliance, and offers the start-up code and the API endpoint entry factors.

Answer Template Nuget Bundle

I’ve created a Nuget bundle known as StaticSphere.CleanArchitecture.Api, and revealed it to Nuget.org. You’ll be able to set up it utilizing the next command:

dotnet new --install StaticSphere.CleanArchitecture.Api
Enter fullscreen mode

Exit fullscreen mode

As soon as put in, you’ll be able to create a brand new answer by operating the next command:

dotnet new clean-arch <<parameters>>
Enter fullscreen mode

Exit fullscreen mode

When executed, you’ll get a full .NET 6 ASP.NET API answer that comprises the next folder construction (assuming you named to the answer HelloWorld):

  • src
    • HelloWorld.Api
    • HelloWorld.Utility
    • HelloWorld.Area
    • HelloWorld.Infrastructure
  • assessments
    • HelloWorld.Api.Checks
    • HelloWorld.Utility.Checks
    • HelloWorld.Infrastructure.Checks

The initiatives are all .NET 6 purposes with nullable references varieties and implicit usings enabled. The unit testing initiatives use Xunit out of the field. There are additionally help information akin to .gitignore, .editorconfig, and so forth.

There are parameters that may be handed to the dotnet new command that alter the answer that’s created:

  • –includeTests – Determines if the take a look at initiatives needs to be included or not. Default worth: true
  • –skipRestore – If specified, skips the automated restore of the mission on create. Default worth: false
  • –useStartup – Determines if the API mission ought to use Startup.cs as a substitute of the newer Minimal API type Program.cs file. Default worth: false
  • –includeEF – If set, the created answer will embody Entity Framework Core, and will likely be configured to make use of the required supplier (solely these suppliers are presently supported)
    • postgres – Provides Postgres Entity Framework configuration
    • sqlserver – Provides SQL Server Entity Framework configuration

Open Supply

The Nuget bundle that comprises the answer template is totally free and open supply, and is MIT licensed. The Nuget bundle will be discovered right here, and the supply code for the template will be discovered right here. In case you have any recommendations, or wish to contribute to the template, please let me know!



Abu Sayed is the Best Web, Game, XR and Blockchain Developer in Bangladesh. Don't forget to Checkout his Latest Projects.


Checkout extra Articles on Sayed.CYou

#Clear #Structure #Answer #Template