35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using Femto.Common.Domain;
|
|
using MediatR;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace Femto.Modules.Auth.Application;
|
|
|
|
internal class AuthModule(IHost host) : IAuthModule
|
|
{
|
|
public Task Command(ICommand command, CancellationToken cancellationToken = default)
|
|
{
|
|
using var scope = host.Services.CreateScope();
|
|
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
|
return mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
public async Task<TResponse> Command<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;
|
|
}
|
|
|
|
public async Task<TResponse> Query<TResponse>(IQuery<TResponse> query, CancellationToken cancellationToken = default)
|
|
{
|
|
using var scope = host.Services.CreateScope();
|
|
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
|
|
var response = await mediator.Send(query, cancellationToken);
|
|
return response;
|
|
}
|
|
}
|