Skip to content

Commit

Permalink
moved to .NET Core 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lkurzyniec committed Dec 17, 2019
1 parent 24d21b3 commit 45764d6
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.402
dotnet-version: 3.1.100

- name: Build sln
run: dotnet build -c Release --no-cache ./HappyCode.NetCoreBoilerplate.sln
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -127,8 +127,7 @@ _TeamCity*
!.axoCover/settings.json

# Coverlet is a Code Coverage Tool
coverage*.json
coverage*.xml
coverage*[.json, .xml, .info]

# Visual Studio code coverage results
*.coverage
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -2,7 +2,7 @@ language: csharp
mono: none
sudo: required
dist: xenial
dotnet: 2.2
dotnet: 3.1.100

branches:
only:
Expand Down
3 changes: 3 additions & 0 deletions Directory.Build.props
@@ -1,4 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Authors>Łukasz Kurzyniec</Authors>
<Copyright>Copyright © happy+code 2019</Copyright>
Expand Down
6 changes: 3 additions & 3 deletions README.md
@@ -1,6 +1,6 @@
# netcore-boilerplate

Boilerplate of API in `.NET Core 2.2`
Boilerplate of API in `.NET Core 3.1`

| Travis CI | GitHub | Codecov |
|:-------------:|:-------------:|:-------------:|
Expand Down Expand Up @@ -78,8 +78,8 @@ of starting an empty project and adding the same snippets each time, you can use

[HappyCode.NetCoreBoilerplate.Db](src/HappyCode.NetCoreBoilerplate.Db)

* Sample migration scripts, both `.sql` and `.cs` - [S001_AddCarTypesTable.sql](src/HappyCode.NetCoreBoilerplate.Db/Scripts/Sql/S001_AddCarTypesTable.sql), [S002_ModifySomeRows.cs](src/HappyCode.NetCoreBoilerplate.Db/Scripts/Code/S002_ModifySomeRows.cs)
* Console application as a simple db migration tool - [Program.cs](src/HappyCode.NetCoreBoilerplate.Db/Program.cs)
* Sample migration scripts, both `.sql` and `.cs` - [S001_AddCarTypesTable.sql](src/HappyCode.NetCoreBoilerplate.Db/Scripts/Sql/S001_AddCarTypesTable.sql), [S002_ModifySomeRows.cs](src/HappyCode.NetCoreBoilerplate.Db/Scripts/Code/S002_ModifySomeRows.cs)

![HappyCode.NetCoreBoilerplate.Db](https://kurzyniec.pl/wp-content/uploads/2019/12/netcore-boilerplate-db.png "HappyCode.NetCoreBoilerplate.Db")

Expand Down Expand Up @@ -148,7 +148,7 @@ Run `dotnet test` command in the root directory, it will look for test projects

## To Do

* feature branch with .NET Core 3.0 (IMHO not yet ready for PROD)
* any idea?

## Be like a star, give me a star! :star:

Expand Down
4 changes: 2 additions & 2 deletions dockerfile
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /work
COPY src .

Expand All @@ -8,7 +8,7 @@ RUN dotnet publish -c Release -o /app

LABEL maintainer="Lukasz Kurzyniec (lkurzyniec@gmail.com)"

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS final
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "HappyCode.NetCoreBoilerplate.Api.dll"]
@@ -1,29 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Api.Analyzers" Version="2.2.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.0" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc5" />
</ItemGroup>

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

</Project>
18 changes: 11 additions & 7 deletions src/HappyCode.NetCoreBoilerplate.Api/Program.cs
@@ -1,23 +1,24 @@
using System;
using System.Threading.Tasks;
using Autofac.Extensions.DependencyInjection;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Configurations;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace HappyCode.NetCoreBoilerplate.Api
{
public static class Program
{
public static void Main(string[] args)
public static async Task Main(string[] args)
{
Log.Logger = SerilogConfigurator.CreateLogger();

try
{
Log.Logger.Information("Starting up");
using var webHost = CreateWebHostBuilder(args).Build();
webHost.Run();
await webHost.RunAsync();
}
catch (Exception ex)
{
Expand All @@ -30,10 +31,13 @@ public static void Main(string[] args)
}
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureServices(services => services.AddAutofac())
.UseStartup<Startup>();
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
14 changes: 9 additions & 5 deletions src/HappyCode.NetCoreBoilerplate.Api/Startup.cs
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Mvc;
using HappyCode.NetCoreBoilerplate.Api.BackgroundServices;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Filters;
using Microsoft.Extensions.Hosting;

namespace HappyCode.NetCoreBoilerplate.Api
{
Expand All @@ -32,7 +33,6 @@ public virtual void ConfigureServices(IServiceCollection services)
})
.AddApiExplorer()
.AddDataAnnotations()
.AddJsonFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Latest);

services.AddHttpContextAccessor();
Expand All @@ -42,7 +42,7 @@ public virtual void ConfigureServices(IServiceCollection services)

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "Simple Api", Version = "v1" });
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Simple Api", Version = "v1" }); //needs to be fixed after official release of Swashbuckle.AspNetCore 5.x
c.DescribeAllParametersInCamelCase();
c.OrderActionsBy(x => x.RelativePath);
});
Expand All @@ -59,16 +59,20 @@ public virtual void ConfigureContainer(ContainerBuilder builder)
ContainerConfigurator.RegisterModules(builder);
}

public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env)
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseHealthChecks("/healthcheck");
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/healthcheck");
});

app.UseMvc();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
Expand Down
@@ -1,20 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.6">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.18" />
</ItemGroup>

</Project>
@@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Content Include="appsettings.json" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\Sql\S001_AddCarTypesTable.sql" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="dbup-sqlserver" Version="4.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="dbup-sqlserver" Version="4.3.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/HappyCode.NetCoreBoilerplate.Db/Program.cs
Expand Up @@ -12,7 +12,7 @@ class Program
{
private static Regex _runPattern = new Regex(@".*");

static int Main(string[] args)
public static int Main(string[] args)
{
var configuration = LoadAppConfiguration();
var upgradeOptions = configuration.GetSection("UpgradeOptions").Get<UpgradeOptions>();
Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand All @@ -14,5 +15,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\HappyCode.NetCoreBoilerplate.Api\HappyCode.NetCoreBoilerplate.Api.csproj" />
</ItemGroup>

</Project>
@@ -1,9 +1,8 @@
using System;
using System.Net.Http;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Hosting;
using Xunit;

namespace HappyCode.NetCoreBoilerplate.Api.IntegrationTests.Infrastructure
Expand All @@ -14,15 +13,18 @@ public class TestServerClientFixture

public TestServerClientFixture()
{
var server = new TestServer(WebHost.CreateDefaultBuilder()
.UseEnvironment("Test")
.ConfigureServices(services => services.AddAutofac())
.UseStartup<TestStartup>())
var host = new HostBuilder()
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHost(webBuilder =>
{
BaseAddress = new Uri("http://localhost:5000")
};
webBuilder
.UseEnvironment("Test")
.UseStartup<TestStartup>()
.UseTestServer();
})
.Start();

Client = server.CreateClient();
Client = host.GetTestClient();
}
}

Expand Down
Expand Up @@ -20,7 +20,6 @@ public TestStartup(IConfiguration configuration)
public override void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddJsonFormatters()
.AddDataAnnotations()
.SetCompatibilityVersion(CompatibilityVersion.Latest);

Expand All @@ -41,15 +40,19 @@ public override void ConfigureContainer(ContainerBuilder builder)
// builder.RegisterType<SomeService>().As<ISomeService>(); //if needed override registration with own test fakes
}

public override void Configure(IApplicationBuilder app, IHostingEnvironment env)
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var employeesContext = app.ApplicationServices.GetService<EmployeesContext>();
EmployeesContextDataFeeder.Feed(employeesContext);

var carsContext = app.ApplicationServices.GetService<CarsContext>();
CarsContextDataFeeder.Feed(carsContext);

app.UseMvc();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
Expand Up @@ -5,7 +5,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Moq" Version="4.13.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Moq.AutoMocker.NETStandard" Version="0.5.0.9" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -16,5 +16,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\HappyCode.NetCoreBoilerplate.Api\HappyCode.NetCoreBoilerplate.Api.csproj" />
</ItemGroup>

</Project>
Expand Up @@ -5,7 +5,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Moq" Version="4.13.0" />
<PackageReference Include="MockQueryable.Moq" Version="3.0.1" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Moq.AutoMocker.NETStandard" Version="0.5.0.9" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -16,5 +17,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\HappyCode.NetCoreBoilerplate.Core\HappyCode.NetCoreBoilerplate.Core.csproj" />
</ItemGroup>

</Project>

1 comment on commit 45764d6

@lkurzyniec
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build failed partially - step with Code Coverage failed because of codecov, which is not ready for .NET Core 3.1.

Please sign in to comment.