Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to dotnet9 #13

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ name: build and test
# the main branch, when either C# or project files changed
on:
push:
branches: [main]
pull_request:
branches: [main]
paths-ignore:
- "README.md"

# Create an environment variable named DOTNET_VERSION
# and set it as "7.0.x"
# and set it as "9.0.x"
env:
DOTNET_VERSION: "8.0.x" # The .NET SDK version to use
DOTNET_VERSION: "9.0.x" # The .NET SDK version to use

# Defines a single job named "build-and-test"
jobs:
Expand All @@ -31,23 +32,27 @@ jobs:
# Each job run contains these five steps
steps:
# 1) Check out the source code so that the workflow can access it.
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# 2) Set up the .NET CLI environment for the workflow to use.
# The .NET version is specified by the environment variable.
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

# 3) Restore the dependencies and tools of a project or solution.
- name: Install dependencies
- name: Restore dependencies
run: dotnet restore

# 4) Build a project or solution and all of its dependencies.
# 4) Check code style and analysis
- name: Format
run: dotnet format --verify-no-changes --verbosity diagnostic

# 5) Build a project or solution and all of its dependencies.
- name: Build
run: dotnet build --configuration Release --no-restore

# 5) Test a project or solution.
# 6) Test a project or solution.
- name: Test
run: dotnet test --no-restore --verbosity normal
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyName>VerticalSliceArchitecture.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>

<AnalysisLevel>8-minimum</AnalysisLevel>
<AnalysisLevel>latest-minimum</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
Expand Down
28 changes: 14 additions & 14 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
<!--ASP.NET-->
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<!-- Entity Framework -->
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="9.0.1" />
<!-- Open source packages -->
<PackageVersion Include="CsvHelper" Version="15.0.10" />
<PackageVersion Include="ErrorOr" Version="1.10.0" />
<PackageVersion Include="FluentValidation" Version="11.9.0" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="MediatR" Version="12.2.0" />
<PackageVersion Include="MediatR" Version="12.4.1" />
<!-- Analyzers -->
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<!-- Tests -->
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
<PackageVersion Include="FluentAssertions" Version="7.1.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="throw" Version="1.4.0" />
<PackageVersion Include="xunit" Version="2.6.5" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Moq" Version="4.16.1" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
</ItemGroup>
</Project>
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Vertical Slice Architecture example in .NET 8
# Vertical Slice Architecture example in .NET 9

Check out my [blog post](https://nadirbad.dev/posts/vetical-slice-architecture-dotnet/) for more details about Vertical Slice Architecture.

Expand All @@ -17,11 +17,12 @@ Loving it? Show your support by giving this project a star!

This project repository is created based on [Clean Architecture solution template by Jason Taylor](https://github.com/jasontaylordev/CleanArchitecture), and it uses technology choices and application business logic from this template.

- [ASP.NET API with .NET 8](https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-8.0)
- [ASP.NET API with .NET 9](https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-9.0)
- CQRS with [MediatR](https://github.com/jbogard/MediatR)
- [FluentValidation](https://fluentvalidation.net/)
- [Entity Framework Core 8](https://docs.microsoft.com/en-us/ef/core/)
- [Entity Framework Core 9](https://docs.microsoft.com/en-us/ef/core/)
- [xUnit](https://xunit.net/), [FluentAssertions](https://fluentassertions.com/), [Moq](https://github.com/moq)
- Result pattern for handling exceptions and errors using [ErrorOr package](https://github.com/amantinband/error-or)

Afterwards, the projects and architecture is refactored towards the Vertical slice architecture style.

Expand Down Expand Up @@ -49,7 +50,7 @@ This projects contains contains all applications logic and shared concerns like

## Getting started

1. Install the latest [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
1. Install the latest [.NET 9 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
2. Navigate to `src/Api` and run `dotnet run` to launch the back end (ASP.NET Core Web API) or via `dotnet run --project src/Api/Api.csproj`

### Build, test and publish application
Expand Down Expand Up @@ -144,6 +145,12 @@ and apply migration and update the database:
dotnet ef database update --project src/Application --startup-project src/Api
```

### Testing API endpoints

You can test the endpoints using tools like [Postman](https://www.postman.com/) or simply from VS Code using the [REST Client extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client).

Find the example requests in the `requests` folder in the root of the project.

## Code analysis

Developers should follow Microsoft's [C# Coding Conventions](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions).
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "latestMinor",
"version": "8.0.100"
"version": "9.0.100"
}
}
5 changes: 1 addition & 4 deletions src/Application/Features/TodoLists/GetTodos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public async Task<ErrorOr<TodosVm>> Handle(GetTodosQuery request, CancellationTo
{
return new TodosVm
{
PriorityLevels = Enum.GetValues(typeof(PriorityLevel))
.Cast<PriorityLevel>()
.Select(p => new PriorityLevelDto((int)p, p.ToString()))
.ToList(),
PriorityLevels = [.. Enum.GetValues<PriorityLevel>().Select(p => new PriorityLevelDto((int)p, p.ToString()))],

Lists = await _context.TodoLists
.AsNoTracking()
Expand Down
Loading