|
@@ -1,8 +1,10 @@
|
|
|
using FileStorage.Repository.SqlSugar.Extensions;
|
|
|
+using Microsoft.AspNetCore.Authentication;
|
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
using Serilog;
|
|
|
using XF.Domain.Dependency;
|
|
|
using XF.Domain.Filters;
|
|
|
+using XF.Utility.Authorize;
|
|
|
|
|
|
namespace FileStorage.Host;
|
|
|
|
|
@@ -24,14 +26,13 @@ internal static class StartupExtensions
|
|
|
// Add services to the container.
|
|
|
services.BatchInjectServices();
|
|
|
|
|
|
-
|
|
|
services.AddScoped<IFileStorage, DefaultFileStorage>();
|
|
|
|
|
|
|
|
|
//var storageConfig = configuration.GetSection(nameof(StorageConfiguration)).Get<StorageConfiguration>();
|
|
|
//if(storageConfig == null || string.IsNullOrEmpty(storageConfig.Impt) || storageConfig.Impt == FileStorageConsts.LocalImpt)
|
|
|
//{
|
|
|
-
|
|
|
+
|
|
|
//}
|
|
|
|
|
|
services.AddControllers(options =>
|
|
@@ -43,23 +44,27 @@ internal static class StartupExtensions
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
services.AddEndpointsApiExplorer();
|
|
|
|
|
|
- //swagger
|
|
|
- services.RegisterSwagger();
|
|
|
-
|
|
|
- /* CORS */
|
|
|
- services.RegisterCors(configuration, CorsOrigins);
|
|
|
+ services
|
|
|
+ //swagger
|
|
|
+ .RegisterSwagger()
|
|
|
+ // CORS
|
|
|
+ .RegisterCors(configuration, CorsOrigins)
|
|
|
+ //mapster
|
|
|
+ .RegisterMapper()
|
|
|
+ //sqlsugar
|
|
|
+ .AddSqlSugar(configuration);
|
|
|
|
|
|
- //mapster
|
|
|
- services.RegisterMapper();
|
|
|
+ //auth
|
|
|
+ var ids4Options = configuration.GetSection(nameof(Ids4AuthorizeOptions)).Get<Ids4AuthorizeOptions>();
|
|
|
+ services.RegisterIds4Authorize(ids4Options);
|
|
|
|
|
|
////mediatr
|
|
|
//services.AddMediatR(d =>
|
|
|
//{
|
|
|
// d.RegisterServicesFromAssembly(typeof(ApplicationStartupExtensions).Assembly);
|
|
|
//});
|
|
|
-
|
|
|
- //sqlsugar
|
|
|
- services.AddSqlSugar(configuration);
|
|
|
+
|
|
|
+
|
|
|
////cache
|
|
|
//services.AddCache(d =>
|
|
|
// {
|
|
@@ -74,14 +79,14 @@ internal static class StartupExtensions
|
|
|
// config.DisableDataAnnotationsValidation = true;
|
|
|
//})
|
|
|
// .AddValidatorsFromAssembly(typeof(AppContractsStartupExtensions).Assembly);
|
|
|
-
|
|
|
+
|
|
|
return builder.Build();
|
|
|
}
|
|
|
|
|
|
internal static WebApplication ConfigurePipelines(this WebApplication app)
|
|
|
{
|
|
|
app.UseSerilogRequestLogging();
|
|
|
-
|
|
|
+
|
|
|
var swaggerEnable = app.Configuration.GetSection("Swagger").Get<bool>();
|
|
|
// Configure the HTTP request pipeline.
|
|
|
if (swaggerEnable)
|
|
@@ -94,16 +99,18 @@ internal static class StartupExtensions
|
|
|
app.UseAuthentication();
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
- app.MapControllers();
|
|
|
-
|
|
|
if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Uploads")))
|
|
|
{
|
|
|
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Uploads"));
|
|
|
};
|
|
|
- app.UseStaticFiles(new StaticFileOptions {
|
|
|
- FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),"Uploads")),
|
|
|
+ app.UseStaticFiles(new StaticFileOptions
|
|
|
+ {
|
|
|
+ FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Uploads")),
|
|
|
RequestPath = new PathString("/Uploads")
|
|
|
});
|
|
|
+
|
|
|
+ app.MapControllers();
|
|
|
+
|
|
|
return app;
|
|
|
}
|
|
|
}
|