private static TResponse ExecutingWithResponse <TRequest, TResponse>( ILogger logger, IComponentContext componentContext, TRequest request ) where TRequest : IRequest, new() where TResponse : IResponse, new() { var openType = typeof(IRequestHandlerWithResponse <,>); // Generic open type. var type = openType.MakeGenericType(typeof(TRequest), typeof(TResponse)); // Type is your runtime type. if (!componentContext.IsRegistered(type)) { logger.LogError("Execute: " + type.FullName + " - " + " Request: " + typeof(TRequest).FullName + " Response: " + typeof(TResponse).FullName + " not registered!"); return(new TResponse()); } try { var requestHandler = componentContext.Resolve(type); var methodInfo = type.GetMethod("Execute"); //logger.LogTrace("Execute: " + openType.Name + " - " + " Request: " + typeof(TRequest).FullName + " Response: " + typeof(TResponse).FullName); return((TResponse)methodInfo?.Invoke(requestHandler, new[] { (object)request })); } catch (Exception ex) { throw LogExceptionManager.LogException(logger, ex); } }
private static void Executing <TRequest>(ILogger logger, IComponentContext componentContext, TRequest request) where TRequest : IRequest, new() { try { var openType = typeof(IRequestHandler <>); // Generic open type. var type = openType.MakeGenericType(typeof(TRequest)); // Type is your runtime type. if (!componentContext.IsRegistered(type)) { logger.LogError("Execute: " + type.FullName + " - " + " Request: " + typeof(TRequest).FullName + " not registered!"); return; } try { var requestHandler = componentContext.Resolve(type); var methodInfo = type.GetMethod("Execute"); //logger.LogTrace("Execute: " + openType.Name + " - " + " Request: " + typeof(TRequest).FullName + " Response: void"); if (methodInfo != null) { methodInfo.Invoke(requestHandler, new[] { (object)request }); } } catch (Exception ex) { throw LogExceptionManager.LogException(logger, ex); } } catch (Exception eex) { if (eex.InnerException != null) { throw eex.InnerException; } throw; } }
private static void Executing(ILogger logger, IComponentContext componentContext, string serviceName) { try { //var openType = typeof(IRequestHandler); // Generic open type. var type = typeof(IRequestHandler); // Type is your runtime type. if (!componentContext.IsRegisteredWithName <IRequestHandler>(serviceName)) { logger.LogError("Execute: " + type.FullName + " - " + serviceName + " not registered!"); return; } try { var requestHandler = componentContext.ResolveNamed <IRequestHandler>(serviceName); var methodInfo = type.GetMethod("Execute"); //logger.LogTrace("Execute: " + type.Name + " - " + serviceName + " Response: void"); if (methodInfo != null) { methodInfo.Invoke(requestHandler, null); } } catch (Exception ex) { throw LogExceptionManager.LogException(logger, ex); } } catch (Exception eex) { if (eex.InnerException != null) { throw eex.InnerException; } throw; } }