stuff
This commit is contained in:
parent
14fd359ea8
commit
a4ef2b4a20
26 changed files with 331 additions and 78 deletions
11
Femto.Modules.Auth/Application/AuthApplication.cs
Normal file
11
Femto.Modules.Auth/Application/AuthApplication.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Femto.Modules.Auth.Application;
|
||||
|
||||
public class AuthApplication(IHost host) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await host.RunAsync(stoppingToken);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using Microsoft.Extensions.Hosting;
|
|||
|
||||
namespace Femto.Modules.Auth.Application;
|
||||
|
||||
internal class AuthenticationModule(IHost host) : IAuthenticationModule
|
||||
internal class AuthModule(IHost host) : IAuthModule
|
||||
{
|
||||
public async Task<TResponse> PostCommand<TResponse>(ICommand<TResponse> command, CancellationToken cancellationToken = default)
|
||||
{
|
|
@ -4,47 +4,46 @@ using MediatR;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Femto.Modules.Auth.Application;
|
||||
|
||||
public static class AuthenticationStartup
|
||||
public static class AuthStartup
|
||||
{
|
||||
public static void InitializeAuthenticationModule(this IServiceCollection rootContainer, string connectionString)
|
||||
public static void InitializeAuthenticationModule(
|
||||
this IServiceCollection rootContainer,
|
||||
string connectionString
|
||||
)
|
||||
{
|
||||
var hostBuilder = Host.CreateDefaultBuilder();
|
||||
hostBuilder.ConfigureServices(services => ConfigureServices(services, connectionString));
|
||||
var host = hostBuilder.Build();
|
||||
rootContainer.AddScoped<IAuthenticationModule>(_ => new AuthenticationModule(host));
|
||||
rootContainer.AddScoped<IAuthModule>(_ => new AuthModule(host));
|
||||
rootContainer.AddHostedService(services => new AuthApplication(host));
|
||||
}
|
||||
|
||||
private static void ConfigureServices(IServiceCollection services, string connectionString)
|
||||
{
|
||||
services.AddDbContext<AuthContext>(
|
||||
builder =>
|
||||
{
|
||||
builder.UseNpgsql(connectionString);
|
||||
builder.UseSnakeCaseNamingConvention();
|
||||
});
|
||||
|
||||
services.AddMediatR(c => c.RegisterServicesFromAssembly(typeof(AuthenticationStartup).Assembly));
|
||||
|
||||
services.AddDbContext<AuthContext>(builder =>
|
||||
{
|
||||
builder.UseNpgsql(connectionString);
|
||||
builder.UseSnakeCaseNamingConvention();
|
||||
});
|
||||
|
||||
services.AddMediatR(c => c.RegisterServicesFromAssembly(typeof(AuthStartup).Assembly));
|
||||
|
||||
services.AddDbContext<AuthContext>(builder =>
|
||||
{
|
||||
builder.UseNpgsql();
|
||||
builder.UseSnakeCaseNamingConvention();
|
||||
builder.EnableSensitiveDataLogging();
|
||||
});
|
||||
|
||||
services.AddScoped<DbContext>(s => s.GetRequiredService<AuthContext>());
|
||||
|
||||
|
||||
services.ConfigureDomainServices<AuthContext>();
|
||||
|
||||
services.AddMediatR(c =>
|
||||
{
|
||||
c.RegisterServicesFromAssembly(typeof(AuthenticationStartup).Assembly);
|
||||
c.RegisterServicesFromAssembly(typeof(AuthStartup).Assembly);
|
||||
});
|
||||
|
||||
services.AddTransient(
|
||||
typeof(IPipelineBehavior<,>),
|
||||
typeof(SaveChangesPipelineBehaviour<,>)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ internal class ValidateSessionCommandHandler(AuthContext context)
|
|||
if (user is null)
|
||||
throw new InvalidSessionError();
|
||||
|
||||
var session = user.StartNewSession();
|
||||
var session = user.PossiblyRefreshSession(request.SessionId);
|
||||
|
||||
return new ValidateSessionResult(
|
||||
new Session(session.Id, session.Expires),
|
||||
|
|
|
@ -2,7 +2,7 @@ using Femto.Common.Domain;
|
|||
|
||||
namespace Femto.Modules.Auth.Application;
|
||||
|
||||
public interface IAuthenticationModule
|
||||
public interface IAuthModule
|
||||
{
|
||||
Task<TResponse> PostCommand<TResponse>(ICommand<TResponse> command, CancellationToken cancellationToken = default);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue