BlazorApp/BlazorApp/Program.cs

71 lines
2.1 KiB
C#

using BlazorApp;
using BlazorApp.Client;
using BlazorApp.Components;
using BlazorApp.Data.Context;
using BlazorApp.Interfaces.Repositories;
using BlazorApp.Interfaces.Services;
using BlazorApp.Models.Config;
using BlazorApp.Repositories.Database;
using BlazorApp.Repositories.InMemory;
using BlazorApp.Services;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
builder.Services.AddBlazorBootstrap();
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("ApplicationDB")));
builder.Services.AddControllers();
builder.Services.AddMemoryCache();
InMemoryCacheConfiguration inMemoryCacheConfiguration = new InMemoryCacheConfiguration();
builder.Configuration.GetSection(nameof(InMemoryCacheConfiguration)).Bind(inMemoryCacheConfiguration);
builder.Services.AddSingleton(inMemoryCacheConfiguration);
builder.Services.AddScoped<ICustomerService, CustomerService>();
builder.Services.AddScoped<ICustomerRepository, CustomerDatabaseRepository>();
if (inMemoryCacheConfiguration.Enabled)
{
builder.Services.Decorate<ICustomerRepository, CustomerInMemoryRepository>();
}
builder.Services.AddClientServices();
var app = builder.Build();
app.ExecuteDbMigration();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// 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.MapControllers();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(BlazorApp.Client._Imports).Assembly);
app.BootstrapMockCustomers();
app.Run();