104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
using GPW.CORE.Api.Data;
|
|
using GPW.CORE.Data;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using StackExchange.Redis;
|
|
using StackExchange.Redis.Extensions.Core.Configuration;
|
|
using StackExchange.Redis.Extensions.Newtonsoft;
|
|
using System.Globalization;
|
|
using System.Text.Json.Serialization;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// configuration setup
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
// Redis
|
|
var connStringRedis = configuration.GetConnectionString("Redis");
|
|
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
// abilitazione x email management con MailKit
|
|
//builder.Services.AddTransient<IEmailSender, MailKitEmailSender>();
|
|
builder.Services.AddSingleton<IEmailSender, MailKitEmailSender>();
|
|
// recupero email reversed
|
|
string revPwd = configuration["ExternalProviders:MailKit:SMTP:Password"] ?? "";
|
|
string pwd = "";
|
|
foreach (char c in revPwd)
|
|
{
|
|
pwd = c + pwd;
|
|
}
|
|
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 = pwd;
|
|
options.Sender_EMail = configuration["ExternalProviders:MailKit:SMTP:SenderEmail"] ?? "";
|
|
options.Sender_Name = configuration["ExternalProviders:MailKit:SMTP:SenderName"] ?? "";
|
|
});
|
|
|
|
builder.Services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
configuration.GetSection("Redis").Get<RedisConfiguration>();
|
|
//options.Configuration = configuration.GetSection("Redis").GetConnectionString("Redis");
|
|
});
|
|
|
|
builder.Services.AddControllers()
|
|
.AddJsonOptions(c => c.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
|
|
|
|
builder.Services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>((options) =>
|
|
{
|
|
List<RedisConfiguration> newConf = new List<RedisConfiguration>();
|
|
var currConf = configuration.GetSection("Redis").Get<RedisConfiguration>();
|
|
if (currConf != null)
|
|
{
|
|
newConf.Add(currConf);
|
|
}
|
|
return newConf;
|
|
//return configuration.GetSection("Redis").Get<RedisConfiguration>();
|
|
});
|
|
|
|
builder.Services.AddSingleton<ApiDataService>();
|
|
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
// cultura IT...
|
|
var supportedCultures = new[]{
|
|
new CultureInfo("it-IT")
|
|
};
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture("it-IT"),
|
|
SupportedCultures = supportedCultures,
|
|
FallBackToParentCultures = false
|
|
});
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|