mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-08 07:43:51 +00:00
Initial commit
This commit is contained in:
parent
1d9d051759
commit
9656378279
557 changed files with 182300 additions and 0 deletions
87
vscode/PracticalApps/Northwind.Mvc/Program.cs
Normal file
87
vscode/PracticalApps/Northwind.Mvc/Program.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
// Section 1 - import namespaces
|
||||
using Microsoft.AspNetCore.Identity; // IdentityUser
|
||||
using Microsoft.EntityFrameworkCore; // UseSqlServer, UseSqlite
|
||||
using Northwind.Mvc.Data; // ApplicationDbContext
|
||||
using Packt.Shared; // AddNorthwindContext extension method
|
||||
using System.Net.Http.Headers; // MediaTypeWithQualityHeaderValue
|
||||
|
||||
// Section 2 - configure the host web server including services
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
||||
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseSqlServer(connectionString));
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
||||
.AddRoles<IdentityRole>() // enable role management
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
/*
|
||||
// if you are using SQL Server
|
||||
string? sqlServerConnection = builder.Configuration
|
||||
.GetConnectionString("NorthwindConnection");
|
||||
|
||||
if (sqlServerConnection is null)
|
||||
{
|
||||
Console.WriteLine("SQL Server database connection string is missing!");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddNorthwindContext(sqlServerConnection);
|
||||
}
|
||||
*/
|
||||
|
||||
// if you are using SQLite default is ..\Northwind.db
|
||||
builder.Services.AddNorthwindContext();
|
||||
|
||||
builder.Services.AddHttpClient(name: "Northwind.WebApi",
|
||||
configureClient: options =>
|
||||
{
|
||||
options.BaseAddress = new Uri("https://localhost:5002/");
|
||||
options.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue(
|
||||
mediaType: "application/json", quality: 1.0));
|
||||
});
|
||||
|
||||
builder.Services.AddHttpClient(name: "Minimal.WebApi",
|
||||
configureClient: options =>
|
||||
{
|
||||
options.BaseAddress = new Uri("https://localhost:5003/");
|
||||
options.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue(
|
||||
"application/json", 1.0));
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Section 3 -
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseMigrationsEndPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
app.MapRazorPages();
|
||||
|
||||
// Section 4 - start the host web server listening for HTTP requests
|
||||
app.Run();
|
||||
Loading…
Add table
Add a link
Reference in a new issue