一个适用于垂直切片架构的企业就绪解决方案模板。此模板只是应用垂直切片架构的一种方式。
SSW Vertical Slice Architecture Template
An enterprise ready solution template for Vertical Slice Architecture. This template is just one way to apply the Vertical Slice Architecture.
Read more on SSW Rules to Better Vertical Slice Architecture
dotnet new cli template - to get you started quickly
Agent skills - the conventions are executable, not just documented
/add-entity and /add-slice ship in .claude/skills/Aspire
Domain Driven Design Patterns
⚡ FastEndpoints - developer friendly alternative to Minimal APIs.
OpenAPI/Swagger - 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
REPR (Request-Endpoint-Response) Pattern - for structured endpoints
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
dotnet-ef, restored from the solution's tool manifest:dotnet tool restoremigrations resource shells out to dotnet ef database update on every start,
so the app won't boot without it. .config/dotnet-tools.json pins the version that matches the
solution's EF Core packages — a mismatched global dotnet-ef will not do.dotnet new install SSW.VerticalSliceArchitecture.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 Sprout
cd SproutCreate a new solution
dotnet new ssw-vsa[!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-vsa --name {{SolutionName}}Restore the local tools (first run only)
dotnet tool restoreRun the solution
aspire start[!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.
A full Vertical Slice is a set of files across the domain, persistence, and feature layers:
src/WebApi/Common/Domain/*src/WebApi/Common/Persistence/*src/WebApi/Features/*The template ships skills that scaffold all of this for you. In Claude Code:
/add-entity # domain object, strongly typed ID, spec, EF config, DbSet, Vogen registration, migration
/add-slice # one use case — endpoint, request, response, validator, summary — plus testsRun /add-entity first when the use case needs a domain type that doesn't exist yet, then /add-slice. The skills live in .claude/skills/, and the conventions they follow are documented in CLAUDE.md and .claude/rules/. Using a different agent? Point it at .claude/skills/add-slice/SKILL.md — they're plain markdown.
/add-slice adds a slice — one use case in its own folder. It creates the Feature and its route Group as well, but only when the slice is the first one in that Feature. CONTEXT.md defines both terms.
To do it by hand instead, copy an existing feature such as Heroes and rename it. Two steps are easy to miss:
Register the strongly typed ID
This project uses strongly typed IDs, which require registration in the VogenEfCoreConverters class. Miss this and the app throws on startup — it isn't a compile error:
// Register the newly created Entity ID here
[EfCoreConverter]
internal sealed partial class VogenEfCoreConverters;Add a migration for the new Entity
dotnet ef migrations add AddPerson --project src/WebApi/WebApi.csproj --startup-project src/WebApi/WebApi.csproj --output-dir Common/Persistence/MigrationsMigrations are their own Aspire resource. The AppHost declares it with
AddEFMigrations("migrations"), and RunDatabaseUpdateOnStart() runs
dotnet ef database update before the API starts. Both the migrations and the ApplicationDbContext
live in src/WebApi, so every command below targets that one project.
dotnet ef migrations add YourMigrationName --project src/WebApi/WebApi.csproj --startup-project src/WebApi/WebApi.csproj --output-dir Common/Persistence/MigrationsNothing needs to be running for this — no database, no AppHost. Scaffolding a migration only needs the model.
Locally, .NET Aspire handles this for you — just start the project. The migrations resource
runs to completion, then the seeder and api resources start. Watch its progress in the
Aspire Dashboard like any other resource.
On Azure this is a deployment step rather than something the app does to itself — see Deploying to Azure.
dotnet ef migrations remove --project src/WebApi/WebApi.csproj --startup-project src/WebApi/WebApi.csproj --force--force is always required here, and not because anything needs to be running. Aspire injects
the connection string into the migrations and api resources at runtime, so a dotnet ef you
run yourself never gets one. EF can't reach the database to check whether the migration has been
applied, and refuses to guess — without --force it stops at
The ConnectionString property has not been initialized.
--force skips that check, so mind what the check was for. If you've started the app since
adding the migration, the migrations resource has already applied it, and deleting the files
leaves the database ahead of the model. Recover by dropping the local database — the Drop
Database command on the AppDb resource, from the dashboard or via
aspire resource AppDb drop-database — or by rolling forward with a new migration that undoes
the change. Rolling forward is the safer habit once a migration has left your machine.
The template can be deployed to Azure via the Azure Developer CLI (AZD). This will setup the following:
The seeder resource is deliberately absent. It's only added to the graph in run mode, so it
never reaches Azure and Bogus data can't land in a deployed database.
Authenticate with Azure
azd auth loginInitialize AZD for the project
azd initDeploy 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.
azd up does not apply migrations. PublishAsMigrationBundle() writes an artifact; it
doesn't run one. Applying it is a step you own.
Publishing produces a self-contained EF Core migration bundle
at efmigrations/migrations in the output directory. Run it against the target database as a
deployment step, after azd provision and before (or alongside) azd deploy:
aspire publish --output-path ./publish
./publish/efmigrations/migrations --connection ""[!IMPORTAN
暂无开放 Issues,或尚未同步最近议题。