mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-07 07:14:02 +00:00
Initial commit
This commit is contained in:
parent
1d9d051759
commit
9656378279
557 changed files with 182300 additions and 0 deletions
68
vscode/PracticalApps/Northwind.WebApi/Program.cs
Normal file
68
vscode/PracticalApps/Northwind.WebApi/Program.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using Microsoft.AspNetCore.Mvc.Formatters; // IOutputFormatter, OutputFormatter
|
||||
using Packt.Shared; // AddNorthwindContext extension method
|
||||
using Northwind.WebApi.Repositories; // ICustomerRepository, CustomerRepository
|
||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddNorthwindContext();
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
WriteLine("Default output formatters:");
|
||||
foreach (IOutputFormatter formatter in options.OutputFormatters)
|
||||
{
|
||||
OutputFormatter? mediaFormatter = formatter as OutputFormatter;
|
||||
if (mediaFormatter is null)
|
||||
{
|
||||
WriteLine($" {formatter.GetType().Name}");
|
||||
}
|
||||
else // OutputFormatter class has SupportedMediaTypes
|
||||
{
|
||||
WriteLine(" {0}, Media types: {1}",
|
||||
arg0: mediaFormatter.GetType().Name,
|
||||
arg1: string.Join(", ",
|
||||
mediaFormatter.SupportedMediaTypes));
|
||||
}
|
||||
}
|
||||
})
|
||||
.AddXmlDataContractSerializerFormatters()
|
||||
.AddXmlSerializerFormatters();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddDbContextCheck<NorthwindContext>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json",
|
||||
"Northwind Service API Version 1");
|
||||
c.SupportedSubmitMethods(new[] {
|
||||
SubmitMethod.Get, SubmitMethod.Post,
|
||||
SubmitMethod.Put, SubmitMethod.Delete });
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseHealthChecks(path: "/howdoyoufeel");
|
||||
|
||||
app.UseMiddleware<SecurityHeaders>();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
Loading…
Add table
Add a link
Reference in a new issue