|
@@ -1,10 +1,13 @@
|
|
-using DataSharing.Repository.Extensions;
|
|
|
|
|
|
+using DataSharing.Application.Services;
|
|
|
|
+using DataSharing.Repository.Extensions;
|
|
using FluentValidation;
|
|
using FluentValidation;
|
|
using FluentValidation.AspNetCore;
|
|
using FluentValidation.AspNetCore;
|
|
using Hotline.Application;
|
|
using Hotline.Application;
|
|
using Mapster;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
+using Polly;
|
|
|
|
+using Polly.Retry;
|
|
using Serilog;
|
|
using Serilog;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Filters;
|
|
using XF.Domain.Filters;
|
|
@@ -17,6 +20,7 @@ namespace DataSharing.Host;
|
|
internal static class StartupExtensions
|
|
internal static class StartupExtensions
|
|
{
|
|
{
|
|
const string CorsOrigins = "CorsOrigins";
|
|
const string CorsOrigins = "CorsOrigins";
|
|
|
|
+
|
|
internal static WebApplication ConfigureServices(this WebApplicationBuilder builder)
|
|
internal static WebApplication ConfigureServices(this WebApplicationBuilder builder)
|
|
{
|
|
{
|
|
var services = builder.Services;
|
|
var services = builder.Services;
|
|
@@ -61,36 +65,44 @@ internal static class StartupExtensions
|
|
services.RegisterMapper();
|
|
services.RegisterMapper();
|
|
|
|
|
|
//mediatr
|
|
//mediatr
|
|
- services.AddMediatR(d =>
|
|
|
|
- {
|
|
|
|
- d.RegisterServicesFromAssembly(typeof(ApplicationStartupExtensions).Assembly);
|
|
|
|
- });
|
|
|
|
|
|
+ services.AddMediatR(d => { d.RegisterServicesFromAssembly(typeof(ApplicationStartupExtensions).Assembly); });
|
|
|
|
|
|
//sqlsugar
|
|
//sqlsugar
|
|
services.AddSqlSugar(configuration);
|
|
services.AddSqlSugar(configuration);
|
|
|
|
|
|
//cache
|
|
//cache
|
|
services.AddCache(d =>
|
|
services.AddCache(d =>
|
|
- {
|
|
|
|
- var cacheConfig = configuration.GetSection("Cache").Get<CacheOptions>();
|
|
|
|
- cacheConfig.Adapt(d);
|
|
|
|
- d.Prefix = "DataSharing";
|
|
|
|
- d.TopicName = "Dsharing-topic";
|
|
|
|
- });
|
|
|
|
|
|
+ {
|
|
|
|
+ var cacheConfig = configuration.GetSection("Cache").Get<CacheOptions>();
|
|
|
|
+ cacheConfig.Adapt(d);
|
|
|
|
+ d.Prefix = "DataSharing";
|
|
|
|
+ d.TopicName = "Dsharing-topic";
|
|
|
|
+ });
|
|
|
|
|
|
//validator
|
|
//validator
|
|
- services.AddFluentValidationAutoValidation(config =>
|
|
|
|
- {
|
|
|
|
- config.DisableDataAnnotationsValidation = true;
|
|
|
|
- })
|
|
|
|
|
|
+ services.AddFluentValidationAutoValidation(config => { config.DisableDataAnnotationsValidation = true; })
|
|
.AddValidatorsFromAssembly(typeof(ApplicationStartupExtensions).Assembly);
|
|
.AddValidatorsFromAssembly(typeof(ApplicationStartupExtensions).Assembly);
|
|
|
|
|
|
//mq
|
|
//mq
|
|
services.AddMq(configuration);
|
|
services.AddMq(configuration);
|
|
|
|
|
|
|
|
+ //retry pipeline
|
|
|
|
+ services.AddResiliencePipeline(StrategyDefaults.RetryStrategy, d =>
|
|
|
|
+ {
|
|
|
|
+ d.AddRetry(new RetryStrategyOptions
|
|
|
|
+ {
|
|
|
|
+ Delay = TimeSpan.FromSeconds(5),
|
|
|
|
+ //BackoffType = DelayBackoffType.Constant,
|
|
|
|
+ //// UseJitter = true,
|
|
|
|
+ //MaxDelay = TimeSpan.FromSeconds(10),
|
|
|
|
+ MaxRetryAttempts = 10
|
|
|
|
+ });
|
|
|
|
+ //.AddTimeout(TimeSpan.FromSeconds(5));
|
|
|
|
+ });
|
|
|
|
+
|
|
//services.AddSingleton<IAuthorizationPolicyProvider, AuthorizationPolicyProvider>();
|
|
//services.AddSingleton<IAuthorizationPolicyProvider, AuthorizationPolicyProvider>();
|
|
//services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
|
|
//services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
|
|
-
|
|
|
|
|
|
+
|
|
return builder.Build();
|
|
return builder.Build();
|
|
}
|
|
}
|
|
|
|
|