Skip to content

Commit

Permalink
Adds support for .NET 6 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb authored Nov 11, 2021
1 parent e5b0c8a commit 4dddba2
Show file tree
Hide file tree
Showing 40 changed files with 968 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ build_script:
- ps: .\dotnet-install.ps1 -Runtime dotnet -Version 2.0.7 # Required for building the netcoreapp2.1 FrontendWeb (Razor throws an error otherwise)
- ps: .\dotnet-install.ps1 -Runtime dotnet -Version 2.1.23
- ps: .\dotnet-install.ps1 -Runtime dotnet -Version 3.1.10
- ps: .\dotnet-install.ps1 -Version 5.0.101
- ps: .\dotnet-install.ps1 -Runtime dotnet -Version 5.0.12
- ps: .\dotnet-install.ps1 -Version 6.0.100
- ps: .\build.ps1

test: off
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ matrix:
dist: xenial
sudo: required
mono: none
dotnet: 5.0.101
dotnet: 6.0.100
addons:
apt:
sources:
Expand All @@ -17,6 +17,7 @@ matrix:
- dotnet-hosting-2.0.7
- aspnetcore-runtime-2.1
- aspnetcore-runtime-3.1
- aspnetcore-runtime-5.0

env:
global:
Expand Down
38 changes: 38 additions & 0 deletions OpenTracing.Contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrdersApi", "samples\net5.0
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrafficGenerator", "samples\net5.0\TrafficGenerator\TrafficGenerator.csproj", "{3369C8DF-DCC2-4934-BBA0-222BE6E5D649}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net6.0", "net6.0", "{03935477-E35E-4EEE-9944-8742E0CB5CFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomersApi", "samples\net6.0\CustomersApi\CustomersApi.csproj", "{872A3B2E-1A28-4B3C-A83D-7C99513B36FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrontendWeb", "samples\net6.0\FrontendWeb\FrontendWeb.csproj", "{4756D99B-BAA2-4B9E-AAE3-F521C38134DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrdersApi", "samples\net6.0\OrdersApi\OrdersApi.csproj", "{73108F76-DAF0-48A1-9FE7-F17395672316}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "samples\net6.0\Shared\Shared.csproj", "{85F652F4-BF5E-4CBF-BD1F-5BE305DC4589}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrafficGenerator", "samples\net6.0\TrafficGenerator\TrafficGenerator.csproj", "{AE063835-3A23-4037-900D-9FFCC3234C8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -148,6 +160,26 @@ Global
{3369C8DF-DCC2-4934-BBA0-222BE6E5D649}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3369C8DF-DCC2-4934-BBA0-222BE6E5D649}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3369C8DF-DCC2-4934-BBA0-222BE6E5D649}.Release|Any CPU.Build.0 = Release|Any CPU
{872A3B2E-1A28-4B3C-A83D-7C99513B36FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{872A3B2E-1A28-4B3C-A83D-7C99513B36FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{872A3B2E-1A28-4B3C-A83D-7C99513B36FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{872A3B2E-1A28-4B3C-A83D-7C99513B36FB}.Release|Any CPU.Build.0 = Release|Any CPU
{4756D99B-BAA2-4B9E-AAE3-F521C38134DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4756D99B-BAA2-4B9E-AAE3-F521C38134DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4756D99B-BAA2-4B9E-AAE3-F521C38134DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4756D99B-BAA2-4B9E-AAE3-F521C38134DD}.Release|Any CPU.Build.0 = Release|Any CPU
{73108F76-DAF0-48A1-9FE7-F17395672316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73108F76-DAF0-48A1-9FE7-F17395672316}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73108F76-DAF0-48A1-9FE7-F17395672316}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73108F76-DAF0-48A1-9FE7-F17395672316}.Release|Any CPU.Build.0 = Release|Any CPU
{85F652F4-BF5E-4CBF-BD1F-5BE305DC4589}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85F652F4-BF5E-4CBF-BD1F-5BE305DC4589}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85F652F4-BF5E-4CBF-BD1F-5BE305DC4589}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85F652F4-BF5E-4CBF-BD1F-5BE305DC4589}.Release|Any CPU.Build.0 = Release|Any CPU
{AE063835-3A23-4037-900D-9FFCC3234C8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE063835-3A23-4037-900D-9FFCC3234C8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE063835-3A23-4037-900D-9FFCC3234C8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE063835-3A23-4037-900D-9FFCC3234C8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -174,6 +206,12 @@ Global
{E68B95C3-E0B4-489A-9FE9-3A46183D7AE9} = {064684F8-44D7-4151-81E0-79FCEF3EB744}
{9185D267-C28C-471E-80DF-9621F03FDF6B} = {064684F8-44D7-4151-81E0-79FCEF3EB744}
{3369C8DF-DCC2-4934-BBA0-222BE6E5D649} = {064684F8-44D7-4151-81E0-79FCEF3EB744}
{03935477-E35E-4EEE-9944-8742E0CB5CFD} = {36333C22-54F7-403C-ABC4-BECE4EE3F52D}
{872A3B2E-1A28-4B3C-A83D-7C99513B36FB} = {03935477-E35E-4EEE-9944-8742E0CB5CFD}
{4756D99B-BAA2-4B9E-AAE3-F521C38134DD} = {03935477-E35E-4EEE-9944-8742E0CB5CFD}
{73108F76-DAF0-48A1-9FE7-F17395672316} = {03935477-E35E-4EEE-9944-8742E0CB5CFD}
{85F652F4-BF5E-4CBF-BD1F-5BE305DC4589} = {03935477-E35E-4EEE-9944-8742E0CB5CFD}
{AE063835-3A23-4037-900D-9FFCC3234C8F} = {03935477-E35E-4EEE-9944-8742E0CB5CFD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {832F86C2-4B74-4259-8073-04EE0C37FBCD}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _**IMPORTANT:** OpenTracing and OpenCensus have merget to form **[OpenTelemetry]

## Supported .NET versions

This project currently only supports apps targeting `netcoreapp2.1` (.NET Core 2.1), `netcoreapp3.1` (.NET Core 3.1) or net5.0 (.NET 5.0)!
This project currently only supports apps targeting `netcoreapp2.1` (.NET Core 2.1), `netcoreapp3.1` (.NET Core 3.1), net5.0 (.NET 5.0), or .NET 6.0!

This project DOES NOT support the full .NET framework as that uses different instrumentation code.

Expand Down
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sdk": {
"version": "5.0.101"
"version": "6.0.100",
"rollForward": "feature"
}
}
4 changes: 2 additions & 2 deletions launch-sample.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[CmdletBinding(PositionalBinding = $false)]
param(
[ValidateSet("net5.0", "netcoreapp3.1", "netcoreapp2.1")]
[string] $Framework = "net5.0"
[ValidateSet("net6.0", "net5.0", "netcoreapp3.1", "netcoreapp2.1")]
[string] $Framework = "net6.0"
)

dotnet build
Expand Down
40 changes: 40 additions & 0 deletions samples/net6.0/CustomersApi/Controllers/CustomersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Samples.CustomersApi.DataStore;

namespace Samples.CustomersApi.Controllers
{
[Route("customers")]
public class CustomersController : Controller
{
private readonly CustomerDbContext _dbContext;
private readonly ILogger _logger;

public CustomersController(CustomerDbContext dbContext, ILogger<CustomersController> logger)
{
_dbContext = dbContext;
_logger = logger;
}

[HttpGet]
public IActionResult Index()
{
return Json(_dbContext.Customers.ToList());
}

[HttpGet("{id:int}")]
public IActionResult Index(int id)
{
var customer = _dbContext.Customers.FirstOrDefault(x => x.CustomerId == id);

if (customer == null)
return NotFound();

// ILogger events are sent to OpenTracing as well!
_logger.LogInformation("Returning data for customer {CustomerId}", id);

return Json(customer);
}
}
}
17 changes: 17 additions & 0 deletions samples/net6.0/CustomersApi/CustomersApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\..\..\src\OpenTracing.Contrib.NetCore\OpenTracing.Contrib.NetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.0" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions samples/net6.0/CustomersApi/DataStore/CustomerDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using Shared;

namespace Samples.CustomersApi.DataStore
{
public class CustomerDbContext : DbContext
{
public CustomerDbContext(DbContextOptions<CustomerDbContext> options)
: base(options)
{
}

public DbSet<Customer> Customers { get; set; }

public void Seed()
{
if (Database.EnsureCreated())
{
Database.Migrate();

Customers.Add(new Customer(1, "Marcel Belding"));
Customers.Add(new Customer(2, "Phyllis Schriver"));
Customers.Add(new Customer(3, "Estefana Balderrama"));
Customers.Add(new Customer(4, "Kenyetta Lone"));
Customers.Add(new Customer(5, "Vernita Fernald"));
Customers.Add(new Customer(6, "Tessie Storrs"));

SaveChanges();
}
}
}
}
50 changes: 50 additions & 0 deletions samples/net6.0/CustomersApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shared;

namespace Samples.CustomersApi
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseStartup<Startup>()
.UseUrls(Constants.CustomersUrl);
})
.ConfigureServices(services =>
{
// Registers and starts Jaeger (see Shared.JaegerServiceCollectionExtensions)
services.AddJaeger();

// Enables OpenTracing instrumentation for ASP.NET Core, CoreFx, EF Core
services.AddOpenTracing(builder =>
{
builder.ConfigureAspNetCore(options =>
{
// We don't need any tracing data for our health endpoint.
options.Hosting.IgnorePatterns.Add(ctx => ctx.Request.Path == "/health");
});

builder.ConfigureEntityFrameworkCore(options =>
{
// This is an example for how certain EF Core commands can be ignored.
// As en example, we're ignoring the "PRAGMA foreign_keys=ON;" commands that are executed by Sqlite.
// Remove this code to see those statements.
options.IgnorePatterns.Add(cmd => cmd.Command.CommandText.StartsWith("PRAGMA"));
});
});

});
}
}
}
12 changes: 12 additions & 0 deletions samples/net6.0/CustomersApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"CustomersApi": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
54 changes: 54 additions & 0 deletions samples/net6.0/CustomersApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Samples.CustomersApi.DataStore;

namespace Samples.CustomersApi
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Adds a Sqlite DB to show EFCore traces.
services
.AddDbContext<CustomerDbContext>(options =>
{
options.UseSqlite("Data Source=DataStore/customers.db");
});

services.AddMvc();

services.AddHealthChecks()
.AddDbContextCheck<CustomerDbContext>();
}

public void Configure(IApplicationBuilder app)
{
// Load some dummy data into the db.
BootstrapDataStore(app.ApplicationServices);

app.UseDeveloperExceptionPage();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/health");
});
}

private void BootstrapDataStore(IServiceProvider serviceProvider)
{
using (var scope = serviceProvider.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<CustomerDbContext>();
dbContext.Seed();
}
}
}
}
10 changes: 10 additions & 0 deletions samples/net6.0/CustomersApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Loading

0 comments on commit 4dddba2

Please sign in to comment.