예제 #1
0
        private async Task <object> SendMessage <TMessage>(TMessage msg, CancellationToken cancellationToken)
            where TMessage : IMessage
        {
            var receiveContext = (IReceiveContext <TMessage>)Activator.CreateInstance(typeof(ReceiveContext <>).MakeGenericType(msg.GetType()), msg);

            RegisterServiceIfRequired(receiveContext);

            var task = _globalPipe.Connect((IReceiveContext <IMessage>)receiveContext, cancellationToken);

            return(await task.ConfigureAwait(false));
        }
예제 #2
0
        private async Task <object> SendMessage <TMessage>(TMessage msg, CancellationToken cancellationToken)
            where TMessage : IMessage
        {
            var receiveContext = (IReceiveContext <TMessage>)Activator.CreateInstance(typeof(ReceiveContext <>).MakeGenericType(msg.GetType()), msg);

            receiveContext.RegisterService(this);
            if (!receiveContext.TryGetService(out IPublishPipe <IPublishContext <IEvent> > _))
            {
                receiveContext.RegisterService(_publishPipe);
            }

            if (!receiveContext.TryGetService(out ICommandReceivePipe <IReceiveContext <ICommand> > _))
            {
                receiveContext.RegisterService(_commandReceivePipe);
            }

            if (!receiveContext.TryGetService(out IEventReceivePipe <IReceiveContext <IEvent> > _))
            {
                receiveContext.RegisterService(_eventReceivePipe);
            }

            if (!receiveContext.TryGetService(out IRequestReceivePipe <IReceiveContext <IRequest> > _))
            {
                receiveContext.RegisterService(_requestPipe);
            }

            var task = _globalPipe.Connect((IReceiveContext <IMessage>)receiveContext, cancellationToken);

            return(await task.ConfigureAwait(false));
        }
예제 #3
0
        private async Task <object> SendMessage <TMessage>(TMessage msg)
            where TMessage : IMessage
        {
            var receiveContext = (IReceiveContext <TMessage>)Activator.CreateInstance(typeof(ReceiveContext <>).MakeGenericType(msg.GetType()), msg);

            receiveContext.RegisterService(this);
            IPublishPipe <IPublishContext <IEvent> > publishPipeInContext;

            if (!receiveContext.TryGetService(out publishPipeInContext))
            {
                receiveContext.RegisterService(_publishPipe);
            }

            ICommandReceivePipe <IReceiveContext <ICommand> > commandReceivePipeInContext;

            if (!receiveContext.TryGetService(out commandReceivePipeInContext))
            {
                receiveContext.RegisterService(_commandReceivePipe);
            }

            IEventReceivePipe <IReceiveContext <IEvent> > eventReceivePipeInContext;

            if (!receiveContext.TryGetService(out eventReceivePipeInContext))
            {
                receiveContext.RegisterService(_eventReceivePipe);
            }

            IRequestReceivePipe <IReceiveContext <IRequest> > requestPipeInContext;

            if (!receiveContext.TryGetService(out requestPipeInContext))
            {
                receiveContext.RegisterService(_requestPipe);
            }

            var task = _globalPipe.Connect((IReceiveContext <IMessage>)receiveContext);
            await task.ConfigureAwait(false);

            return(task.Result);
        }