mirror of
https://github.com/dotnet/skills.git
synced 2026-09-20 09:49:54 +08:00
e4670b33a1
* Add code testing agent agents + tests PoC * Remove AssertionEvaluator.cs change (moved to dev/jankrivanek/agents-evals)
77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ContosoUniversity.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.IO;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add Entity Framework
|
|
builder.Services.AddDbContext<SchoolContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"),
|
|
sqlServerOptionsAction: sqlOptions =>
|
|
{
|
|
sqlOptions.EnableRetryOnFailure(
|
|
maxRetryCount: 5,
|
|
maxRetryDelay: TimeSpan.FromSeconds(30),
|
|
errorNumbersToAdd: null);
|
|
}));
|
|
|
|
// Add MVC services
|
|
builder.Services.AddControllersWithViews();
|
|
builder.Services.AddSession();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Initialize database
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var services = scope.ServiceProvider;
|
|
try
|
|
{
|
|
var context = services.GetRequiredService<SchoolContext>();
|
|
DbInitializer.Initialize(context);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var logger = services.GetRequiredService<ILogger<Program>>();
|
|
logger.LogError(ex, "An error occurred creating the DB.");
|
|
}
|
|
}
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles(); // For wwwroot
|
|
|
|
// Serve legacy Content folder
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
|
|
Path.Combine(builder.Environment.ContentRootPath, "Content")),
|
|
RequestPath = "/Content"
|
|
});
|
|
|
|
// Serve legacy Scripts folder
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
|
|
Path.Combine(builder.Environment.ContentRootPath, "Scripts")),
|
|
RequestPath = "/Scripts"
|
|
});
|
|
|
|
app.UseRouting();
|
|
app.UseSession();
|
|
|
|
app.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
app.Run(); |