fix injectionses

This commit is contained in:
john 2025-05-21 00:19:49 +02:00
parent b93115d787
commit cd078ca643
11 changed files with 119 additions and 55 deletions

View file

@ -1,37 +1,29 @@
using Femto.Common.Domain;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Femto.Modules.Blog.Application;
internal class BlogModule(IHost host) : IBlogModule
internal class BlogModule(IMediator mediator) : IBlogModule
{
public async Task PostCommand(ICommand command, CancellationToken cancellationToken = default)
public async Task Command(ICommand command, CancellationToken cancellationToken = default)
{
using var scope = host.Services.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
await mediator.Send(command, cancellationToken);
}
public async Task<TResponse> PostCommand<TResponse>(
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> PostQuery<TResponse>(
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;
}