public async Task <TResult> DispatchAsync <TResult>(AsyncQuery <TResult> query) { var handlerType = typeof(IAsyncQueryHandler <,>).MakeGenericType(query.GetType(), typeof(TResult)); var handler = (IAsyncQueryHandler <TResult>)_serviceProvider.GetService(handlerType); return(await handler.HandleAsync(query)); }