-
Notifications
You must be signed in to change notification settings - Fork 72
.NET 8 Upgrade #104
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
Open
chrisb92
wants to merge
2
commits into
opentracing-contrib:master
Choose a base branch
from
chrisb92:dotnet8
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
.NET 8 Upgrade #104
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.100", | ||
"version": "8.0.100", | ||
"rollForward": "feature" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</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="[8.0.0,9)" /> | ||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="[8.0.0,9)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
31 changes: 31 additions & 0 deletions
31
samples/net8.0/CustomersApi/DataStore/CustomerDbContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Shared; | ||
|
||
namespace CustomersApi.DataStore; | ||
|
||
public class CustomerDbContext : DbContext | ||
{ | ||
public CustomerDbContext(DbContextOptions<CustomerDbContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Customer> Customers => Set<Customer>(); | ||
|
||
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(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using CustomersApi.DataStore; | ||
using Microsoft.EntityFrameworkCore; | ||
using Shared; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.WebHost.UseUrls(Constants.CustomersUrl); | ||
|
||
// Registers and starts Jaeger (see Shared.JaegerServiceCollectionExtensions) | ||
builder.Services.AddJaeger(); | ||
|
||
// Enables OpenTracing instrumentation for ASP.NET Core, CoreFx, EF Core | ||
builder.Services.AddOpenTracing(ot => | ||
{ | ||
ot.ConfigureAspNetCore(options => | ||
{ | ||
// We don't need any tracing data for our health endpoint. | ||
options.Hosting.IgnorePatterns.Add(ctx => ctx.Request.Path == "/health"); | ||
}); | ||
|
||
ot.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")); | ||
}); | ||
}); | ||
|
||
// Adds a Sqlite DB to show EFCore traces. | ||
builder.Services.AddDbContext<CustomerDbContext>(options => | ||
{ | ||
options.UseSqlite("Data Source=DataStore/customers.db"); | ||
}); | ||
|
||
builder.Services.AddHealthChecks() | ||
.AddDbContextCheck<CustomerDbContext>(); | ||
|
||
|
||
var app = builder.Build(); | ||
|
||
|
||
// Load some dummy data into the db. | ||
using (var scope = app.Services.CreateScope()) | ||
{ | ||
var dbContext = scope.ServiceProvider.GetRequiredService<CustomerDbContext>(); | ||
dbContext.Seed(); | ||
} | ||
|
||
|
||
// Configure the HTTP request pipeline. | ||
|
||
app.MapGet("/", () => "Customers API"); | ||
|
||
app.MapHealthChecks("/health"); | ||
|
||
app.MapGet("/customers", async (CustomerDbContext dbContext) => await dbContext.Customers.ToListAsync()); | ||
|
||
app.MapGet("/customers/{id}", async (int id, CustomerDbContext dbContext, ILogger<Program> logger) => | ||
{ | ||
var customer = await dbContext.Customers.FirstOrDefaultAsync(x => x.CustomerId == id); | ||
|
||
if (customer == null) | ||
return Results.NotFound(); | ||
|
||
// ILogger events are sent to OpenTracing as well! | ||
logger.LogInformation("Returning data for customer {CustomerId}", id); | ||
|
||
return Results.Ok(customer); | ||
}); | ||
|
||
app.Run(); |
12 changes: 12 additions & 0 deletions
12
samples/net8.0/CustomersApi/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Text; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Newtonsoft.Json; | ||
using Shared; | ||
|
||
namespace FrontendWeb.Controllers; | ||
|
||
public class HomeController : Controller | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public HomeController(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> PlaceOrder() | ||
{ | ||
ViewBag.Customers = await GetCustomers(); | ||
return View(new PlaceOrderCommand { ItemNumber = "ABC11", Quantity = 1 }); | ||
} | ||
|
||
[HttpPost, ValidateAntiForgeryToken] | ||
public async Task<IActionResult> PlaceOrder(PlaceOrderCommand cmd) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
ViewBag.Customers = await GetCustomers(); | ||
return View(cmd); | ||
} | ||
|
||
string body = JsonConvert.SerializeObject(cmd); | ||
|
||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Post, | ||
RequestUri = new Uri(Constants.OrdersUrl + "orders"), | ||
Content = new StringContent(body, Encoding.UTF8, "application/json") | ||
}; | ||
|
||
await _httpClient.SendAsync(request); | ||
|
||
return RedirectToAction("Index"); | ||
} | ||
|
||
private async Task<IEnumerable<SelectListItem>> GetCustomers() | ||
{ | ||
var request = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(Constants.CustomersUrl + "customers") | ||
}; | ||
|
||
var response = await _httpClient.SendAsync(request); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var body = await response.Content.ReadAsStringAsync(); | ||
|
||
return JsonConvert.DeserializeObject<List<Customer>>(body) | ||
.Select(x => new SelectListItem { Value = x.CustomerId.ToString(), Text = x.Name }); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\Shared.csproj" /> | ||
<ProjectReference Include="..\..\..\src\OpenTracing.Contrib.NetCore\OpenTracing.Contrib.NetCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Shared; | ||
|
||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.WebHost.UseUrls(Constants.FrontendUrl); | ||
|
||
// Registers and starts Jaeger (see Shared.JaegerServiceCollectionExtensions) | ||
builder.Services.AddJaeger(); | ||
|
||
// Enables OpenTracing instrumentation for ASP.NET Core, CoreFx, EF Core | ||
builder.Services.AddOpenTracing(); | ||
|
||
builder.Services.AddSingleton<HttpClient>(); | ||
|
||
builder.Services.AddMvc(); | ||
|
||
|
||
var app = builder.Build(); | ||
|
||
|
||
// Configure the HTTP request pipeline. | ||
|
||
app.MapDefaultControllerRoute(); | ||
|
||
app.Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"FrontendWeb": { | ||
"commandName": "Project", | ||
"launchBrowser": false, | ||
"launchUrl": "http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using IHttpClientFactory to create HttpClient instances instead of registering a singleton; this approach better manages DNS updates and socket exhaustion in production scenarios.
Copilot uses AI. Check for mistakes.