Skip to content

Commit

Permalink
Fix scope & add void middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jun 4, 2024
1 parent e587908 commit 7af3626
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/Shiny.Mediator/Impl/DefaultRequestSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@ public class DefaultRequestSender(IServiceProvider services) : IRequestSender
{
public async Task Send(IRequest request, CancellationToken cancellationToken)
{
// using var scope = services.CreateScope();
// var handlers = scope.ServiceProvider.GetServices<IRequestHandler<TRequest>>().ToList();
// AssertRequestHandlers(handlers.Count, request);
//
// await this.ExecuteMiddleware(
// scope,
// (IRequest<Unit>)request,
// async () =>
// {
// await handlers
// .First()
// .Handle(request, cancellationToken)
// .ConfigureAwait(false);
// return Unit.Value;
// },
// cancellationToken
// )
// .ConfigureAwait(false);
throw new BadImageFormatException();
using var scope = services.CreateScope();
var wrapperType = typeof(RequestWrapper<,>).MakeGenericType([request.GetType(), typeof(Unit)]);
var wrapperMethod = wrapperType.GetMethod("Handle", BindingFlags.Public | BindingFlags.Instance)!;
var wrapper = Activator.CreateInstance(wrapperType);
var task = (Task<Unit>)wrapperMethod.Invoke(wrapper, [scope.ServiceProvider, request, cancellationToken])!;
await task.ConfigureAwait(false);
}


Expand All @@ -37,7 +24,7 @@ public async Task<TResult> Request<TResult>(IRequest<TResult> request, Cancellat
var wrapperType = typeof(RequestWrapper<,>).MakeGenericType([request.GetType(), typeof(TResult)]);
var wrapperMethod = wrapperType.GetMethod("Handle", BindingFlags.Public | BindingFlags.Instance)!;
var wrapper = Activator.CreateInstance(wrapperType);
var task = (Task<TResult>)wrapperMethod.Invoke(wrapper, [services, request, cancellationToken])!;
var task = (Task<TResult>)wrapperMethod.Invoke(wrapper, [scope.ServiceProvider, request, cancellationToken])!;
var result = await task.ConfigureAwait(false);
return result;
}
Expand Down

0 comments on commit 7af3626

Please sign in to comment.