SSW 清洁架构模板
This is a template for creating a new project using Clean Architecture, leveraging SSW Rules & SSW's over 30 years of experience developing software in the Microsoft space.
dotnet new cli template - to get you started quickly
Aspire
Dashboard
Resource orchestration
Observability
Simple dev setup - automatic provisioning of database server, schema, and data
Domain Driven Design Patterns
AggregateRoot
Entity
ValueObject
DomainEvent
Minimal Endpoints - because it's fast & simple. ⚡
OpenAPI/Scalar - easily document your API
Global Exception Handling - it's important to handle exceptions in a consistent way & protect sensitive information
️ Entity Framework Core - for data access
Specification Pattern - abstract EF Core away from your business logic
CQRS - for separation of concerns
MediatR - for decoupling your application
ErrorOr - fluent result pattern (instead of exceptions)
FluentValidation - for validating requests
Strongly Typed IDs - to combat primitive obsession
CustomerId type into methods instead of int, or GuidDirectory.Build.Props
⚖️ EditorConfig - comes with the SSW.EditorConfig
Testing
Architecture Tests
Install the SSW CA template
dotnet new install SSW.CleanArchitecture.Template[!NOTE] The template only needs to be installed once. Running this command again will update your version of the template.
Create a new directory
mkdir Northwind365
cd Northwind365Create a new solution
dotnet new ssw-ca[!NOTE]
nameis optional; if you don't specify it, the directory name will be used as the solution name and project namespaces.
Alternatively, you can specify the name and output directory as follows:
dotnet new ssw-ca --name {{SolutionName}} --output .\Create a query
cd src/Application/UseCases
mkdir {{FeatureName}}
cd {{FeatureName}}
dotnet new ssw-ca-query --name {{QueryName}} --entityName {{Entity}} --slnName {{SolutionName}}Create a command
cd src/Application/UseCases
mkdir {{FeatureName}}
cd {{FeatureName}}
dotnet new ssw-ca-command --name {{CommandName}} --entityName {{Entity}} --slnName {{SolutionName}}Run the solution
aspire run[!NOTE] The first time you run the solution, it may take a while to download the docker images, create the DB, and seed the data.
Due to .NET Aspire orchestrating the application startup and migration runner, EF migrations need to be handled a little differently to normal.
Adding new migrations is still the same old command you would expect, but with a couple of specific parameters to account for the separation of concerns. This can be performed via native dotnet tooling or through the Aspire CLI:
dotnet ef migrations add YourMigrationName --project ./src/Infrastructure/Infrastructure.csproj --startup-project ./src/WebApi/WebApi.csproj --output-dir ./Persistence/Migrationsaspire exec --resource api -- dotnet ef migrations add YourMigrationName --project ../Infrastructure/Infrastructure.csproj --output-dir ./Persistence/Migrations.NET Aspire handles this for you - just start the project!
This is where things need to be done a little differently and requires the Aspire CLI.
exec function:aspire config set features.execCommandEnabled trueaspire exec --resource api -- dotnet ef migrations remove --project ..\Infrastructure --force[!NOTE] The
--forceflag is needed because .NET Aspire will start the application when this command is run, which triggers the migrations to run. This will apply your migrations to the database, and make EF Core unhappy when it tries to delete the latest migration. This should therefore be used with caution - a safer approach is to "roll forward" and create new migrations that safely undo the undesired change(s).
The template can be deployed to Azure via the Azure Developer CLI (AZD). This will setup the following:
Authenticate with Azure
azd auth loginInitialize AZD for the project
azd initUpdate environment variables
azd env set ASPNETCORE_ENVIRONMENT DevelopmentDeploy to Azure
azd up[!NOTE]
azd upcombinesazd provisionandazd deploycommands to create the resources and deploy the application. If running this from a CI/CD pipeline, you can useazd provisionandazd deployseparately in the appropriate places.
Template will be published to NuGet.org when changes are made to CleanArchitecture.nuspec on the main branch.
version attribute in CleanArchitecture.nuspecpackage GitHub Action will run and publish the new version to NuGet.org[!NOTE] We are now using CalVer for versioning. The version number should be in the format
YYYY.M.D(e.g.2024.2.12).
If you're interested in learning more about Clean Architecture SSW offers two events:
You're interested learning more about Clean Architecture, please see this excellent video by Matt Goldman:
Alternatively, SSW has many great rules about Clean Architecture:
You can also find a collection of commumity projects built on Clean Architecture here:
Contributions, issues and feature requests are welcome! See Contributing for more information.
暂无开放 Issues,或尚未同步最近议题。