Added redis
This commit is contained in:
parent
d7cd8f4e41
commit
3dc6bffe63
|
@ -1,8 +1,13 @@
|
|||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
|
||||
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Diagnostics.Metrics;
|
||||
using Microsoft.Extensions.Options;
|
||||
using StackExchange.Redis;
|
||||
using Tomlyn.Extensions.Configuration;
|
||||
using Wave.Components;
|
||||
using Wave.Components.Account;
|
||||
|
@ -21,6 +26,27 @@
|
|||
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
||||
builder.Services.AddControllers();
|
||||
|
||||
#region Data Protection & Redis
|
||||
|
||||
if (builder.Configuration.GetConnectionString("Redis") is { } redisUri) {
|
||||
var redis = ConnectionMultiplexer.Connect(redisUri);
|
||||
builder.Services.AddDataProtection()
|
||||
.PersistKeysToStackExchangeRedis(redis)
|
||||
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration() {
|
||||
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
|
||||
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
|
||||
});
|
||||
} else {
|
||||
builder.Services.AddDataProtection()
|
||||
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration() {
|
||||
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
|
||||
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
|
||||
});
|
||||
Console.WriteLine("No Redis connection string found.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Authentication & Authorization
|
||||
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
|
@ -80,6 +106,7 @@
|
|||
builder.Services.AddScoped<IEmailSender<ApplicationUser>, SmtpEmailSender>();
|
||||
} else {
|
||||
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
|
||||
Console.WriteLine("No Email provider configured.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.5.0" />
|
||||
<PackageReference Include="MailKit" Version="4.3.0" />
|
||||
<PackageReference Include="Markdig" Version="0.34.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
|
||||
|
|
|
@ -14,11 +14,14 @@ services:
|
|||
- database:db
|
||||
environment:
|
||||
- "WAVE_ConnectionStrings__DefaultConnection=Host=db; Username=wave; Password=development"
|
||||
- "WAVE_ConnectionStrings__Redis=redis,password=development"
|
||||
volumes:
|
||||
- wave-files:/app/files
|
||||
- wave-config:/configuration
|
||||
networks:
|
||||
- wave
|
||||
depends_on:
|
||||
- database
|
||||
database:
|
||||
image: postgres:16.1-alpine
|
||||
restart: unless-stopped
|
||||
|
@ -30,10 +33,19 @@ services:
|
|||
- wave-db:/var/lib/postgresql/data
|
||||
networks:
|
||||
- wave
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
restart: unless-stopped
|
||||
command: redis-server --requirepass development --save 60 1 --loglevel warning
|
||||
volumes:
|
||||
- wave-redis:/data
|
||||
networks:
|
||||
- wave
|
||||
|
||||
volumes:
|
||||
wave-files:
|
||||
wave-config:
|
||||
wave-db:
|
||||
wave-redis:
|
||||
networks:
|
||||
wave:
|
Loading…
Reference in a new issue