-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5b0c8a
commit 4dddba2
Showing
40 changed files
with
968 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,5 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "5.0.101" | ||
"version": "6.0.100", | ||
"rollForward": "feature" | ||
} | ||
} |
This file contains 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
40 changes: 40 additions & 0 deletions
40
samples/net6.0/CustomersApi/Controllers/CustomersController.cs
This file contains 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,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); | ||
} | ||
} | ||
} |
This file contains 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,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
32
samples/net6.0/CustomersApi/DataStore/CustomerDbContext.cs
This file contains 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,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(); | ||
} | ||
} | ||
} | ||
} |
This file contains 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,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
12
samples/net6.0/CustomersApi/Properties/launchSettings.json
This file contains 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 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,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(); | ||
} | ||
} | ||
} | ||
} |
This file contains 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" | ||
} | ||
} | ||
} |
Oops, something went wrong.