115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.UI;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using StackExchange.Redis;
|
|
using System.Globalization;
|
|
using System.Text.Json.Serialization;
|
|
using WebDoorCreator.Data;
|
|
using WebDoorCreator.Data.Services;
|
|
using WebDoorCreator.UI.Areas.Identity;
|
|
using WebDoorCreator.UI.Data;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
// configuration setup
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
|
|
// AspNetCore Identity setup
|
|
var connectionString = builder.Configuration.GetConnectionString("Identity.DB");
|
|
|
|
// REDIS setup
|
|
string connStringRedis = configuration.GetConnectionString("Redis");
|
|
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
|
|
// abilitazione x email management con MailKit
|
|
builder.Services.AddTransient<IEmailSender, MailKitEmailSender>();
|
|
builder.Services.Configure<MailKitEmailSenderOptions>(options =>
|
|
{
|
|
options.Host_Address = configuration["ExternalProviders:MailKit:SMTP:Address"];
|
|
options.Host_Port = Convert.ToInt32(configuration["ExternalProviders:MailKit:SMTP:Port"]);
|
|
options.Host_Username = configuration["ExternalProviders:MailKit:SMTP:Account"];
|
|
options.Host_Password = configuration["ExternalProviders:MailKit:SMTP:Password"];
|
|
options.Sender_EMail = configuration["ExternalProviders:MailKit:SMTP:SenderEmail"];
|
|
options.Sender_Name = configuration["ExternalProviders:MailKit:SMTP:SenderName"];
|
|
});
|
|
|
|
|
|
// aggiunta servizi x accesso dati...
|
|
builder.Services.AddControllers()
|
|
.AddJsonOptions(c => c.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
|
options.UseSqlServer(connectionString));
|
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
|
.AddRoles<IdentityRole>()
|
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
|
|
|
builder.Services.AddRazorPages();
|
|
builder.Services.AddServerSideBlazor();
|
|
builder.Services.AddSingleton<WebDoorCreatorService>();
|
|
builder.Services.AddSingleton<WDCRefreshService>();
|
|
builder.Services.AddSingleton<WDCVocabularyService>();
|
|
builder.Services.AddSingleton<QueueDataService>(); ;
|
|
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
builder.Services.AddScoped<WDCUserService>();
|
|
builder.Services.AddScoped<UserManDataService>();
|
|
builder.Services.AddScoped<MessageService>();
|
|
builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
|
|
builder.Services.AddHttpContextAccessor();
|
|
builder.Services.AddBlazoredLocalStorage();
|
|
builder.Services.AddBlazoredSessionStorage();
|
|
var app = builder.Build();
|
|
|
|
// aggiunt base URL x routing corretto
|
|
app.UsePathBase(configuration["RuntimeOpt:BaseUrl"]);
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseMigrationsEndPoint();
|
|
}
|
|
else
|
|
{
|
|
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();
|
|
}
|
|
|
|
|
|
// cultura US...
|
|
var supportedCultures = new[]{
|
|
new CultureInfo("en-US")
|
|
};
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture("en-US"),
|
|
SupportedCultures = supportedCultures,
|
|
FallBackToParentCultures = false
|
|
});
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
app.MapBlazorHub();
|
|
app.MapFallbackToPage("/_Host");
|
|
|
|
app.Run();
|