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

Dotnet7 upgrade #95

Merged
merged 5 commits into from
Jan 22, 2023
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
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.x

- name: Build sln
run: dotnet build -c Release --no-cache /clp:NoSummary ./HappyCode.NetCoreBoilerplate.sln
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.x

- name: Collect code coverage
run: dotnet test -c Release --filter FullyQualifiedName!~LoadTests /maxcpucount:1 /p:WarningLevel=0 /p:CollectCoverage=true /p:CoverletOutput="../" /p:MergeWith="../coverage.json" /p:CoverletOutputFormat=\"json,opencover\" ./HappyCode.NetCoreBoilerplate.sln
Expand Down
21 changes: 4 additions & 17 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
<Project>
<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>11</LangVersion>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<Authors>Łukasz Kurzyniec</Authors>
<Copyright>Copyright © happy+code Łukasz Kurzyniec 2022</Copyright>
<Version>1.2.1</Version>
<Version>1.3.0</Version>
</PropertyGroup>

<PropertyGroup>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)HappyCode.NetCoreBoilerplate.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(ProjectName.EndsWith(`Tests`))' == 'False'">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.33">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</PropertyGroup>
</Project>
61 changes: 61 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnablePackageVersionOverride>false</EnablePackageVersionOverride>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AspNetCore.HealthChecks.MySql" Version="6.0.2" />
<PackageVersion Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
<PackageVersion Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.5" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="2.5.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageVersion Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageVersion Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="dbup-sqlserver" Version="5.0.8" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="AutoFixture" Version="4.17.0" />
<PackageVersion Include="AutoFixture.Xunit2" Version="4.17.0" />
<PackageVersion Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="FluentAssertions" Version="6.9.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="7.0.2" />
<PackageVersion Include="MockQueryable.Moq" Version="7.0.0" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="Moq.AutoMock" Version="3.5.0" />
<PackageVersion Include="NBomber.Http" Version="1.1.1" />
<PackageVersion Include="Verify.Http" Version="4.1.0" />
<PackageVersion Include="Verify.Xunit" Version="19.7.1" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
<ItemGroup Condition="'$(ProjectName.EndsWith(`Tests`))' == 'False'">
<GlobalPackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.33">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions HappyCode.NetCoreBoilerplate.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
docker-compose.yml = docker-compose.yml
dockerfile = dockerfile
HappyCode.NetCoreBoilerplate.ruleset = HappyCode.NetCoreBoilerplate.ruleset
Expand All @@ -31,6 +32,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HappyCode.NetCoreBoilerplat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HappyCode.NetCoreBoilerplate.Api.LoadTests", "test\HappyCode.NetCoreBoilerplate.Api.LoadTests\HappyCode.NetCoreBoilerplate.Api.LoadTests.csproj", "{E18EED63-7FDE-449B-9FA3-27FD677CD3FD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ci", "ci", "{C20F30D0-1383-4834-805F-6526300F4D2D}"
ProjectSection(SolutionItems) = preProject
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
.github\workflows\docker.yml = .github\workflows\docker.yml
.github\workflows\dotnetcore.yml = .github\workflows\dotnetcore.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# netcore-boilerplate

Boilerplate of API in ~~`.NET Core 3.1`~~ `.NET 6`
Boilerplate of API in ~~`.NET Core 3.1`~~ `.NET 7`

| GitHub | Codecov |
|:-------------:|:-------------:|
Expand All @@ -11,6 +11,7 @@ of starting an empty project and adding the same snippets each time, you can use

## Source code contains

1. [Central Package Management (CPM)](https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management)
1. ~~[Autofac]~~(https://autofac.org/) (Removed in [PR19](https://github.com/lkurzyniec/netcore-boilerplate/pull/19))
1. [Swagger](https://swagger.io/) + [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle)
1. [FeatureManagement](https://github.com/microsoft/FeatureManagement-Dotnet) (Feature Flags, Feature Toggles)
Expand Down Expand Up @@ -53,7 +54,6 @@ of starting an empty project and adding the same snippets each time, you can use
* `netcore-boilerplate:local`
1. [Serilog](https://serilog.net/)
* Sink: [Async](https://github.com/serilog/serilog-sinks-async)
* Enrich: [CorrelationId](https://github.com/ekmsystems/serilog-enrichers-correlation-id)
1. [DbUp](http://dbup.github.io/) as a db migration tool
1. Continuous integration
* ~~[Travis CI]~~(https://travis-ci.org/) ([travisci.yml](https://github.com/lkurzyniec/netcore-boilerplate/blob/bf65154b63f6a10d6753045c49cd378e53907816/.travis.yml))
Expand Down
11 changes: 6 additions & 5 deletions db/mssql/docker-db-init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#wait for the SQL Server to come up
sleep 30s
#!/bin/bash

echo "running set up script"
#run the setup script to create the DB and the schema in the DB
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P SomeStrongPwd123 -d master -i db-init.sql
echo "waiting 20s for the SQL Server to come up..."
sleep 20s

echo "running set up script..."
/opt/mssql-tools/bin/sqlcmd -S "localhost" -U sa -P "${MSSQL_SA_PASSWORD}" -d master -i db-init.sql
4 changes: 2 additions & 2 deletions db/mssql/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#start SQL Server, start the script to create/setup the DB
/db-init.sh & /opt/mssql/bin/sqlservr
#!/bin/bash
/db-init.sh & /opt/mssql/bin/sqlservr
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ services:
- ./db/mysql/mysql-employees.sql:/docker-entrypoint-initdb.d/init.sql

mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
image: mcr.microsoft.com/mssql/server:2019-latest
user: root
container_name: mssql
command: /bin/bash ./entrypoint.sh
command: /bin/bash /entrypoint.sh
ports:
- 1433:1433
environment:
- ACCEPT_EULA=Y
- MSSQL_PID=Express
- SA_PASSWORD=SomeStrongPwd123
- MSSQL_SA_PASSWORD=SomeStrongPwd123
volumes:
- dbdata:/var/opt/mssql/data
- ./db/mssql/docker-entrypoint.sh:/entrypoint.sh
Expand Down
15 changes: 9 additions & 6 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /work

COPY ./Directory.Build.props ./
COPY ./Directory.Packages.props ./
COPY src/*/*.csproj ./
RUN for projectFile in $(ls *.csproj); \
do \
mkdir -p ${projectFile%.*}/ && mv $projectFile ${projectFile%.*}/; \
done
do \
mkdir -p ${projectFile%.*}/ && mv $projectFile ${projectFile%.*}/; \
done

ENV DOTNET_NOLOGO=true
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
Expand All @@ -15,6 +16,8 @@ RUN dotnet restore /work/HappyCode.NetCoreBoilerplate.Api/HappyCode.NetCoreBoile

COPY src .

# --------------

FROM build AS publish
WORKDIR /work/HappyCode.NetCoreBoilerplate.Api

Expand All @@ -23,9 +26,9 @@ ENV DOTNET_CLI_TELEMETRY_OPTOUT=true

RUN dotnet publish -c Release -o /app --no-restore

LABEL maintainer="Lukasz Kurzyniec ([email protected])"
# --------------

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS final
WORKDIR /app
COPY --from=publish /app .

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.5" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="2.5.1" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="AspNetCore.HealthChecks.MySql" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" />
<PackageReference Include="Serilog.AspNetCore" />
<PackageReference Include="Serilog.Enrichers.Environment" />
<PackageReference Include="Serilog.Sinks.Async" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/HappyCode.NetCoreBoilerplate.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public virtual void ConfigureServices(IServiceCollection services)
.AddDataAnnotations();

//there is a difference between AddDbContext() and AddDbContextPool(), more info https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#dbcontext-pooling and https://stackoverflow.com/questions/48443567/adddbcontext-or-adddbcontextpool
services.AddDbContext<EmployeesContext>(options => options.UseMySql(_configuration.GetConnectionString("MySqlDb"), ServerVersion.Parse("8")), contextLifetime: ServiceLifetime.Transient, optionsLifetime: ServiceLifetime.Singleton);
services.AddDbContext<EmployeesContext>(options => options.UseMySql(_configuration.GetConnectionString("MySqlDb"), ServerVersion.Parse("8.0")), contextLifetime: ServiceLifetime.Transient, optionsLifetime: ServiceLifetime.Singleton);
services.AddDbContextPool<CarsContext>(options => options.UseSqlServer(_configuration.GetConnectionString("MsSqlDb")), poolSize: 10);

services.Configure<ApiKeySettings>(_configuration.GetSection("ApiKey"));
Expand Down
4 changes: 2 additions & 2 deletions src/HappyCode.NetCoreBoilerplate.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
"MySqlDb": "server=mysql;Database=employees;Uid=user;Pwd=simplepwd;",
"MsSqlDb": "Data Source=mssql;Initial Catalog=cars;User ID=user;Password=simplePWD123!"
"MsSqlDb": "Data Source=mssql;Initial Catalog=cars;User ID=user;Password=simplePWD123!;TrustServerCertificate=true;"
},

"PingWebsite": {
Expand Down Expand Up @@ -48,7 +48,7 @@
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithCorrelationIdHeader" ],
"Enrich": [ "FromLogContext", "WithMachineName" ],
"Properties": {
"Application": "HappyCode.NetCoreBoilerplate.Api"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.10" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="dbup-sqlserver" Version="4.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="dbup-sqlserver" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.10" />
<PackageReference Include="Verify.Http" Version="3.0.0" />
<PackageReference Include="Verify.Xunit" Version="18.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="Verify.Http" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\HappyCode.NetCoreBoilerplate.Api\HappyCode.NetCoreBoilerplate.Api.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="NBomber.Http" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NBomber.Http" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
</Project>
Loading