wip
This commit is contained in:
parent
cb9d5e332e
commit
baea64229b
9 changed files with 69 additions and 11 deletions
|
@ -1,8 +1,18 @@
|
|||
using Femto.Common.Domain;
|
||||
using Femto.Modules.Authentication.Data;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Femto.Modules.Authentication.Application;
|
||||
|
||||
internal class AuthenticationModule(IHost host) : IAuthenticationModule
|
||||
{
|
||||
public async Task<TResponse> PostCommand<TResponse>(ICommand<TResponse> command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
using var scope = host.Services.CreateScope();
|
||||
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||
var response = await mediator.Send(command, cancellationToken);
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
using Femto.Common.Infrastructure;
|
||||
using Femto.Common.Infrastructure.Outbox;
|
||||
using Femto.Modules.Authentication.Data;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
@ -12,9 +14,7 @@ public static class AuthenticationStartup
|
|||
{
|
||||
var hostBuilder = Host.CreateDefaultBuilder();
|
||||
hostBuilder.ConfigureServices(services => ConfigureServices(services, connectionString));
|
||||
|
||||
var host = hostBuilder.Build();
|
||||
|
||||
rootContainer.AddScoped<IAuthenticationModule>(_ => new AuthenticationModule(host));
|
||||
}
|
||||
|
||||
|
@ -40,5 +40,10 @@ public static class AuthenticationStartup
|
|||
{
|
||||
c.RegisterServicesFromAssembly(typeof(AuthenticationStartup).Assembly);
|
||||
});
|
||||
|
||||
services.AddTransient(
|
||||
typeof(IPipelineBehavior<,>),
|
||||
typeof(SaveChangesPipelineBehaviour<,>)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
using Femto.Common.Domain;
|
||||
|
||||
namespace Femto.Modules.Authentication.Application.Commands;
|
||||
|
||||
public record LoginCommand(string Username, string Password) : ICommand<Guid>;
|
|
@ -0,0 +1,19 @@
|
|||
using Femto.Modules.Authentication.Data;
|
||||
using Femto.Modules.Authentication.Models;
|
||||
using MediatR;
|
||||
|
||||
namespace Femto.Modules.Authentication.Application.Commands;
|
||||
|
||||
internal class LoginCommandHandler(AuthenticationContext context) : IRequestHandler<LoginCommand, Guid>
|
||||
{
|
||||
public async Task<Guid> Handle(LoginCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = new UserIdentity(request.Username);
|
||||
|
||||
user.SetPassword(request.Password);
|
||||
|
||||
await context.AddAsync(user, cancellationToken);
|
||||
|
||||
return user.Id;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
using Femto.Common.Domain;
|
||||
|
||||
namespace Femto.Modules.Authentication.Application;
|
||||
|
||||
public interface IAuthenticationModule
|
||||
{
|
||||
Task<TResponse> PostCommand<TResponse>(ICommand<TResponse> command, CancellationToken cancellationToken = default);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue