GitHub - SSWConsulting/SSW.VerticalSliceArchitecture: An enterprise ready solution template for Vertical Slice Architecture. This template is just one way to apply the Vertical Slice Architecture. (original) (raw)

SSW Banner

SSW Vertical Slice Architecture Template

๐Ÿค” What is it?

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

โœจ Features

๐ŸŽ‰ Getting Started

Prerequisites

Installing the Template

  1. Install the SSW VSA template
    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.

  1. Create a new directory
  2. Create a new solution

Note

name is 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}}

Running the Solution

  1. Run the solution

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.

  1. Open https://localhost:7255/swagger in your browser to see it running ๏ธ๐Ÿƒโ€โ™‚๏ธ

Adding Features

Adding a Feature Slice

A full Vertical Slice is a set of files across the domain, persistence, and feature layers:

AI coding agents working in this repo know how to scaffold one. The structure is documented in AGENTS.md, so ask your agent to add a feature and it will create these files for you.

  1. Add a new Feature Ask your AI coding agent to scaffold the slice, or copy an existing feature such as Heroes and rename it.
  2. Configure this Feature This project uses strongly typed IDs, which require registration in the VogenEfCoreConverters class:
    // Register the newly created Entity ID here
    [EfCoreConverter]
    internal sealed partial class VogenEfCoreConverters;
  3. Add a migration for the new Entity
    dotnet ef migrations add --project src/WebApi/WebApi.csproj --startup-project src/WebApi/WebApi.csproj --output-dir Common/Database/Migrations PersonTable

EF Migrations

Due to .NET Aspire orchestrating the application startup and migration runner, EF migrations need to be handled a little differently to normal.

Adding a Migration

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:

  1. Run either of following commands from the root of the solution.

dotnet ef migrations add YourMigrationName --project ./src/Infrastructure/Infrastructure.csproj --startup-project ./src/WebApi/WebApi.csproj --output-dir ./Persistence/Migrations

aspire exec --resource api -- dotnet ef migrations add YourMigrationName --project ../Infrastructure/Infrastructure.csproj --output-dir ./Persistence/Migrations

Applying a Migration

.NET Aspire handles this for you - just start the project!

Removing a Migration

This is where things need to be done a little differently and requires the Aspire CLI.

  1. Enable the exec function:

aspire config set features.execCommandEnabled true

  1. Pass the EF migration shell command through Aspire from the root of the solution:

aspire exec --resource api -- dotnet ef migrations remove --project ..\Infrastructure --force

Note

The --force flag 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).

Deploying to Azure

The template can be deployed to Azure via the Azure Developer CLI (AZD). This will setup the following:

Steps to Deploy

  1. Authenticate with Azure
  2. Initialize AZD for the project
  3. Update environment variables
    azd env set ASPNETCORE_ENVIRONMENT Development
  4. Deploy to Azure

Note

azd up combines azd provision and azd deploy commands to create the resources and deploy the application. If running this from a CI/CD pipeline, you can use azd provision and azd deploy separately in the appropriate places.

๐ŸŽ“ Learn More

Vertical Slice Architecture: How Does it Compare to Clean Architecture | .NET Conf 2023

graph TD; subgraph ASP.NET Core Web App subgraph Slices A[Feature A] B[Feature B] end Slices --> |depends on| Common Host --> |depends on| Common Host --> |depends on| Slices ASPNETCore[ASP.NET Core] --> |uses| Host end

Common[Common]

Loading

๐Ÿš€ Publishing Template

Template will be published to NuGet.org when changes are made to VerticalSliceArchitecture.nuspec on the main branch.

Process

  1. Update the version attribute in VerticalSliceArchitecture.nuspec
  2. Merge your PR
  3. package GitHub Action will run and publish the new version to NuGet.org
  4. Create a GitHub release to document the changes

Note

We are now using CalVer for versioning. The version number should be in the format YYYY.M.D (e.g. 2024.2.12).

๐Ÿค Contributing

Contributions, issues and feature requests are welcome! See Contributing for more information.