shopping-cart-blazor-wasm/Server/Program.cs

43 lines
1 KiB
C#
Raw Normal View History

using MediatR;
using Microsoft.EntityFrameworkCore;
using ShoppingCartStarter.Server.Data;
using System.Reflection;
2021-11-09 11:44:08 +01:00
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddMediatR(Assembly.GetExecutingAssembly());
builder.Services.AddDbContext<StoreContext>(options=>options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
2021-11-09 11:44:08 +01:00
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
Database.InitialiseDatabase(app, app.Environment);
2021-11-09 11:44:08 +01:00
}
else
2020-06-19 10:20:16 +02:00
{
2021-11-09 11:44:08 +01:00
app.UseExceptionHandler("/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();
2020-06-19 10:20:16 +02:00
}
2021-11-09 11:44:08 +01:00
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.MapControllers();
app.MapFallbackToFile("index.html");
app.Run();