private void HandleMessage <TMessage>(TMessage message) where TMessage : class, IMessage { try { using (var dependencyScope = RootDependencyScope.CreateChildScope()) { using (var subscriber = dependencyScope.Resolve <IMessageSubscriber <TMessage> >()) { subscriber.Process(message); } } } catch (MessageSubscriptionException) { throw; } catch (Exception exception) { throw new MessageSubscriptionException(typeof(TMessage), exception); } }
private TResponseMessage HandleRequestMessage <TRequestMessage, TResponseMessage>(TRequestMessage requestMessage) where TRequestMessage : class, IRequestMessage <TResponseMessage> where TResponseMessage : class, IResponseMessage { try { using (var dependencyScope = RootDependencyScope.CreateChildScope()) { using (var subscriber = dependencyScope.Resolve <IMessageSubscriber <TRequestMessage, TResponseMessage> >()) { return(subscriber.Process(requestMessage)); } } } catch (MessageSubscriptionException) { throw; } catch (Exception exception) { throw new MessageSubscriptionException(typeof(TRequestMessage), exception); } }
/// <summary> /// Creates a new dependency scope. /// </summary> /// <returns> /// A new dependency scope. /// </returns> /// <exception cref="CreateDependencyScopeException"> /// An exception was raised while attempting to create the scope. /// </exception> /// <exception cref="ObjectDisposedException"> /// The object is disposed. /// </exception> protected IDependencyScope CreateDependencyScope() => RootDependencyScope.CreateChildScope();