Skip to content

Commit

Permalink
docs;
Browse files Browse the repository at this point in the history
target framework;
some packages;
removed mapster in favor of mapperly;
removed newid in favor of the new guidv7 factory;
dockerfile;
  • Loading branch information
yanpitangui committed Nov 12, 2024
1 parent 70e83f3 commit a8cca62
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Setup dotnet
uses: actions/[email protected]
with:
dotnet-version: '8.x'
dotnet-version: '9.x'
- name: Install dotnet-sonarscanner
run: |
dotnet tool install --global dotnet-sonarscanner
Expand Down
25 changes: 12 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
<ItemGroup>
<!-- add your PackageVersion nodes here -->
<PackageVersion Include="Ardalis.Result" Version="10.1.0" />
<PackageVersion Include="Ardalis.Result.AspNetCore" Version="10.0.0" />
<PackageVersion Include="Ardalis.Result.AspNetCore" Version="10.1.0" />
<PackageVersion Include="Ardalis.Result.FluentValidation" Version="10.1.0" />
<PackageVersion Include="EntityFrameworkCore.Exceptions.PostgreSQL" Version="8.1.3" />
<PackageVersion Include="Mapster.EFCore" Version="5.1.1" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.10" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="NewId" Version="4.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageVersion Include="Riok.Mapperly" Version="4.1.0" />
<PackageVersion Include="StronglyTypedId" Version="1.0.0-beta08" />
<PackageVersion Include="FluentValidation" Version="11.10.0" />
<PackageVersion Include="MediatR" Version="12.4.1" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageVersion Include="Bogus" Version="35.6.1" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.10" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Respawn" Version="6.2.1" />
Expand All @@ -37,20 +36,20 @@
</PackageVersion>
<PackageVersion Include="Ben.Demystifier" Version="0.4.1" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="Serilog" Version="4.1.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageVersion Include="Serilog.Exceptions" Version="8.4.0" />
<PackageVersion Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
<PackageVersion Include="Swashbuckle.AspNetCore.Swagger" Version="6.9.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Swagger" Version="7.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="https://github.com/yanpitangui/dotnet-api-boilerplate/tree/main/translations/pt-br/README.md">Português</a>
</p>

A ``.Net 8.0`` WebApi boilerplate / template project. MediatR, Swagger, ~~AutoMapper~~ Mapster, Serilog and more implemented.
A ``.Net 9.0`` WebApi boilerplate / template project. MediatR, Swagger, ~~AutoMapper~~ Mapster, Serilog and more implemented.

[![Build](https://github.com/yanpitangui/dotnet-api-boilerplate/actions/workflows/build.yml/badge.svg)](https://github.com/yanpitangui/dotnet-api-boilerplate/actions/workflows/build.yml)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=yanpitangui_dotnet-api-boilerplate&metric=coverage)](https://sonarcloud.io/dashboard?id=yanpitangui_dotnet-api-boilerplate)
Expand Down
3 changes: 1 addition & 2 deletions src/Boilerplate.Api/Boilerplate.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<UserSecretsId>83093e71-d34c-405d-b8eb-442525b137fc</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
Expand All @@ -10,7 +10,6 @@
<TieredPGO>true</TieredPGO>
<GarbageCollectionAdaptationMode>1</GarbageCollectionAdaptationMode>
<Features>InterceptorsPreview</Features>
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>

</PropertyGroup>

Expand Down
4 changes: 0 additions & 4 deletions src/Boilerplate.Api/Configurations/ApplicationSetup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Boilerplate.Application.Common;
using Boilerplate.Infrastructure;
using MassTransit;
using MassTransit.NewIdProviders;
using Microsoft.Extensions.DependencyInjection;

namespace Boilerplate.Api.Configurations;
Expand All @@ -11,8 +9,6 @@ public static class ApplicationSetup
public static IServiceCollection AddApplicationSetup(this IServiceCollection services)
{
services.AddScoped<IContext, ApplicationDbContext>();
NewId.SetProcessIdProvider(new CurrentProcessIdProvider());

return services;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Boilerplate.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS base
WORKDIR /app
EXPOSE 8080

Expand All @@ -10,7 +10,7 @@ RUN apk add --no-cache icu-libs
# Disable the invariant mode (set in base image)
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
WORKDIR /src
COPY ["./Directory.Packages.props", "./"]
COPY ["src/Boilerplate.Api/Boilerplate.Api.csproj", "src/Boilerplate.Api/"]
Expand Down
4 changes: 2 additions & 2 deletions src/Boilerplate.Application/Boilerplate.Application.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
</PropertyGroup>
Expand All @@ -10,10 +10,10 @@
<PackageReference Include="Ardalis.Result" />
<PackageReference Include="Ardalis.Result.FluentValidation" />
<PackageReference Include="FluentValidation" />
<PackageReference Include="Mapster.EFCore" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" />
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Riok.Mapperly" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Ardalis.Result;
using Boilerplate.Application.Common;
using Mapster;
using MediatR;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -19,9 +18,9 @@ public CreateHeroHandler(IContext context)

public async Task<Result<GetHeroResponse>> Handle(CreateHeroRequest request, CancellationToken cancellationToken)
{
var created = request.Adapt<Domain.Entities.Hero>();
var created = Mapper.ToHeroEntity(request);
_context.Heroes.Add(created);
await _context.SaveChangesAsync(cancellationToken);
return created.Adapt<GetHeroResponse>();
return Mapper.ToHeroDto(created);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Boilerplate.Application.Common;
using Boilerplate.Application.Common.Responses;
using Boilerplate.Application.Extensions;
using Mapster;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System.Linq;
Expand All @@ -27,7 +26,7 @@ public async Task<PaginatedList<GetHeroResponse>> Handle(GetAllHeroesRequest req
.WhereIf(request.HeroType != null, x => x.HeroType == request.HeroType)
.WhereIf(!string.IsNullOrEmpty(request.Team), x => x.Team == request.Team)
.WhereIf(!string.IsNullOrEmpty(request.Individuality), x => EF.Functions.Like(x.Individuality!, $"%{request.Individuality}%"));
return await heroes.ProjectToType<GetHeroResponse>()
return await heroes.ProjectToResponse()
.OrderBy(x => x.Name)
.ToPaginatedListAsync(request.CurrentPage, request.PageSize);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Ardalis.Result;
using Boilerplate.Application.Common;
using Mapster;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System.Threading;
Expand All @@ -22,6 +21,6 @@ public async Task<Result<GetHeroResponse>> Handle(GetHeroByIdRequest request, Ca
var hero = await _context.Heroes.FirstOrDefaultAsync(x => x.Id == request.Id,
cancellationToken: cancellationToken);
if (hero is null) return Result.NotFound();
return hero.Adapt<GetHeroResponse>();
return Mapper.ToHeroDto(hero);
}
}
16 changes: 16 additions & 0 deletions src/Boilerplate.Application/Features/Heroes/Mapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Boilerplate.Application.Features.Heroes.CreateHero;
using Boilerplate.Domain.Entities;
using Riok.Mapperly.Abstractions;
using System.Linq;

namespace Boilerplate.Application.Features.Heroes;

[Mapper]
public static partial class Mapper
{
public static partial Hero ToHeroEntity(CreateHeroRequest dto);

Check warning on line 11 in src/Boilerplate.Application/Features/Heroes/Mapper.cs

View workflow job for this annotation

GitHub Actions / build

The member Id on the mapping target type Boilerplate.Domain.Entities.Hero was not found on the mapping source type Boilerplate.Application.Features.Heroes.CreateHero.CreateHeroRequest

Check warning on line 11 in src/Boilerplate.Application/Features/Heroes/Mapper.cs

View workflow job for this annotation

GitHub Actions / build

The member Id on the mapping target type Boilerplate.Domain.Entities.Hero was not found on the mapping source type Boilerplate.Application.Features.Heroes.CreateHero.CreateHeroRequest

Check warning on line 11 in src/Boilerplate.Application/Features/Heroes/Mapper.cs

View workflow job for this annotation

GitHub Actions / build

The member Id on the mapping target type Boilerplate.Domain.Entities.Hero was not found on the mapping source type Boilerplate.Application.Features.Heroes.CreateHero.CreateHeroRequest
public static partial GetHeroResponse ToHeroDto(Hero entity);

public static partial IQueryable<GetHeroResponse> ProjectToResponse(this IQueryable<Hero> source);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Ardalis.Result;
using Boilerplate.Application.Common;
using Mapster;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System.Threading;
Expand Down Expand Up @@ -32,6 +31,6 @@ public async Task<Result<GetHeroResponse>> Handle(UpdateHeroRequest request,
originalHero.HeroType = request.HeroType;
_context.Heroes.Update(originalHero);
await _context.SaveChangesAsync(cancellationToken);
return originalHero.Adapt<GetHeroResponse>();
return Mapper.ToHeroDto(originalHero);
}
}
3 changes: 1 addition & 2 deletions src/Boilerplate.Domain/Boilerplate.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="NewId" />
<PackageReference Include="StronglyTypedId" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageReference Include="StronglyTypedId.Templates" PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Boilerplate.Domain/Entities/Hero.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Boilerplate.Domain.Entities.Common;
using Boilerplate.Domain.Entities.Enums;
using MassTransit;
using System;

namespace Boilerplate.Domain.Entities;

public class Hero : Entity<HeroId>
{
public override HeroId Id { get; set; } = NewId.NextGuid();
public override HeroId Id { get; set; } = Guid.CreateVersion7();
public string Name { get; set; } = null!;

public string? Nickname { get; set; }
Expand Down
7 changes: 3 additions & 4 deletions src/Boilerplate.Infrastructure/ApplicationUser.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using MassTransit;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity;
using System;

namespace Boilerplate.Infrastructure;

public class ApplicationUser : IdentityUser<Guid>
{
public override Guid Id { get; set; } = NewId.NextSequentialGuid();
public override Guid Id { get; set; } = Guid.CreateVersion7();
}

public class ApplicationRole : IdentityRole<Guid>
{
public override Guid Id { get; set; } = NewId.NextSequentialGuid();
public override Guid Id { get; set; } = Guid.CreateVersion7();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion translations/pt-br/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span>Português</span>
</p>

Um boilerplate de API ``.Net 8.0`` / projeto de template. MediatR, Swagger, ~~AutoMapper~~ Mapster, Serilog, entre outros, implementados.
Um boilerplate de API ``.Net 9.0`` / projeto de template. MediatR, Swagger, ~~AutoMapper~~ Mapster, Serilog, entre outros, implementados.

[![Build](https://github.com/yanpitangui/dotnet-api-boilerplate/actions/workflows/build.yml/badge.svg)](https://github.com/yanpitangui/dotnet-api-boilerplate/actions/workflows/build.yml)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=yanpitangui_dotnet-api-boilerplate&metric=coverage)](https://sonarcloud.io/dashboard?id=yanpitangui_dotnet-api-boilerplate)
Expand Down

0 comments on commit a8cca62

Please sign in to comment.