diff --git a/dotnet/AipsCore/Application/Common/Dispatcher/DispatchException.cs b/dotnet/AipsCore/Application/Common/Dispatcher/DispatchException.cs index 8e0c9c9..6e90bca 100644 --- a/dotnet/AipsCore/Application/Common/Dispatcher/DispatchException.cs +++ b/dotnet/AipsCore/Application/Common/Dispatcher/DispatchException.cs @@ -5,7 +5,7 @@ namespace AipsCore.Application.Common.Dispatcher; public class DispatchException : Exception { - public DispatchException(object commandQuery) - : base($"Error while dispatching '{commandQuery.GetType().Name}'") + public DispatchException(object commandQuery, Exception innerException) + : base($"Error dispatching '{commandQuery.GetType().Name}' because of: {innerException.Message}", innerException) { } } \ No newline at end of file diff --git a/dotnet/AipsCore/Application/Common/Dispatcher/Dispatcher.cs b/dotnet/AipsCore/Application/Common/Dispatcher/Dispatcher.cs index 98c76f9..3bbe44f 100644 --- a/dotnet/AipsCore/Application/Common/Dispatcher/Dispatcher.cs +++ b/dotnet/AipsCore/Application/Common/Dispatcher/Dispatcher.cs @@ -59,11 +59,15 @@ public sealed class Dispatcher : IDispatcher private dynamic ResolveHandler(Type handlerType, object commandOrQuery) { - dynamic? handler = _serviceProvider.GetService(handlerType); - - if (handler is null) + dynamic handler; + + try { - throw new DispatchException(commandOrQuery); + handler = _serviceProvider.GetRequiredService(handlerType); + } + catch (InvalidOperationException serviceProviderException) + { + throw new DispatchException(commandOrQuery, serviceProviderException); } return handler;