コード例 #1
0
        public override IEnumerable <UnsubscribeAction> Subscribe <TComponent>(ISubscriberContext context, TComponent instance)
        {
            Type distributorInterface = typeof(TComponent).GetInterfaces()
                                        .Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IDistributor <>))
                                        .SingleOrDefault();

            if (distributorInterface != null)
            {
                Type messageType = distributorInterface.GetGenericArguments().First();

                if (!context.HasMessageTypeBeenDefined(messageType))
                {
                    context.MessageTypeWasDefined(messageType);

                    yield return(this.FastInvoke <DistributorSubscriber, UnsubscribeAction>(new[] { typeof(TComponent), messageType }, "ConnectDistributor", context, instance));
                }
            }

            distributorInterface = typeof(TComponent).GetInterfaces()
                                   .Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IWorker <>))
                                   .SingleOrDefault();

            if (distributorInterface != null)
            {
                Type messageType = distributorInterface.GetGenericArguments().First();

                Type distributedMessageType = typeof(Distributed <>).MakeGenericType(messageType);

                if (!context.HasMessageTypeBeenDefined(distributedMessageType))
                {
                    context.MessageTypeWasDefined(distributedMessageType);

                    yield return(this.FastInvoke <DistributorSubscriber, UnsubscribeAction>(new[] { typeof(TComponent), messageType }, "ConnectWorker", context, instance));
                }
            }
        }
コード例 #2
0
        private IEnumerable <UnsubscribeAction> ConnectSinks <TComponent, TSaga>(ISubscriberContext context, TComponent instance)
            where TComponent : ISagaWorker <TSaga>
            where TSaga : SagaStateMachine <TSaga>, ISaga
        {
            var saga = FastActivator <TSaga> .Create(CombGuid.Generate());

            var inspector = new SagaStateMachineEventInspector <TSaga>();

            saga.Inspect(inspector);

            foreach (var result in inspector.GetResults())
            {
                Type distributedType = typeof(Distributed <>).MakeGenericType(result.SagaEvent.MessageType);
                if (!context.HasMessageTypeBeenDefined(distributedType))
                {
                    context.MessageTypeWasDefined(distributedType);

                    yield return(ConnectSink(context, instance, result.SagaEvent.MessageType, result.SagaEvent.Event, result.States));
                }
            }
        }