optimise codes

master
Young 7 months ago
parent cdf55587b3
commit 94309870a0

@ -5,6 +5,7 @@ using Infrastructure.Security;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.IdentityModel.Tokens;
namespace Infrastructure.Extensions;
@ -31,12 +32,12 @@ public static class AuthenticationSetup
return services;
}
services.AddSingleton<JwtSecurityTokenHandler>();
services.AddScoped<IUserContext, UserContext>();
services.AddSingleton<DefaultTokenHandler>();
services.AddSingleton<IEncryptionService, EncryptionService>();
services.AddSingleton<IPostConfigureOptions<JwtBearerOptions>, JwtBearerOptionsPostConfigureOptions>();
services.AddSingleton<ITokenBuilder, TokenBuilder>();
services.TryAddSingleton<JwtSecurityTokenHandler>();
services.TryAddScoped<IUserContext, UserContext>();
services.TryAddSingleton<DefaultTokenHandler>();
services.TryAddSingleton<IEncryptionService, EncryptionService>();
services.TryAddSingleton<IPostConfigureOptions<JwtBearerOptions>, JwtBearerOptionsPostConfigureOptions>();
services.TryAddSingleton<ITokenBuilder, TokenBuilder>();
var key = configuration["AUDIENCE_KEY"] ?? audienceOptions.Secret;
ArgumentException.ThrowIfNullOrEmpty(key);

@ -29,9 +29,9 @@ public static class ControllerSetup
})
.ConfigureApiBehaviorOptions(options =>
{
options.InvalidModelStateResponseFactory = context =>
options.InvalidModelStateResponseFactory = _ =>
{
var message = new MessageData(false, "the input wat not valid", 400);
var message = new MessageData(false, "the input value not valid", 400);
return new OkObjectResult(message.Serialize());
};
});

@ -1,5 +1,6 @@
using Infrastructure.Options;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using StackExchange.Redis;
namespace Infrastructure.Extensions;
@ -16,7 +17,7 @@ public static class RedisSetup
return services;
}
services.AddSingleton<ConnectionMultiplexer>(provider =>
services.TryAddSingleton<ConnectionMultiplexer>(_ =>
{
var host = configuration["REDIS_HOST"] ?? redisOptions.Host;
ArgumentException.ThrowIfNullOrEmpty(host);

Loading…
Cancel
Save