예제 #1
0
        public SagaInfo[] GetReactingSagas(AggregateEventInfo aggregateEventInfo)
        {
            if (aggregateEventInfo == null)
            {
                throw new ArgumentNullException(nameof(aggregateEventInfo));
            }

            return(Sagas.Where(x => x.AggregateEvents.Contains(aggregateEventInfo)).ToArray());
        }
예제 #2
0
        public LogicSchema Build()
        {
            var servicesRequiredByAggregates = _aggregateLogicInfos.SelectMany(x => x.Dependencies).SelectMany(x => x.Value);

            foreach (var servicesRequiredByAggregate in servicesRequiredByAggregates)
            {
                if (_serviceInfos.Any(x => x.Type == servicesRequiredByAggregate.Type))
                {
                    var m = $"Some aggregate requires service '{servicesRequiredByAggregate.Name}' but is not presented in schema";
                    throw new LogicSchemaException(m);
                }
            }

            foreach (var sagaInfo in _sagaInfos)
            {
                var eventTypes = sagaInfo.Type.GetTypeInfo().DeclaredMethods
                                 .SelectMany(m => m.GetParameters())
                                 .Select(p => p.ParameterType)
                                 .Where(t => t.GetTypeInfo().IsSubclassOf(typeof(AggregateEvent)))
                                 .Distinct();
                var eventInfosFromAggregates = _aggregateLogicInfos.SelectMany(x => x.Events).ToArray();
                var eventInfos = new List <AggregateEventInfo>();
                foreach (var eventType in eventTypes)
                {
                    var eventInfo = eventInfosFromAggregates.SingleOrDefault(x => x.Type == eventType);
                    if (eventInfo == null)
                    {
                        eventInfo = new AggregateEventInfo(eventType);
                    }
                    eventInfos.Add(eventInfo);
                }
                sagaInfo.AggregateEvents = eventInfos.ToImmutableHashSet();
            }

            foreach (var aggregateLogicInfo in _aggregateLogicInfos)
            {
                foreach (var command in aggregateLogicInfo.AggregateFromLanguage.Commands)
                {
                    var dependencies = _dependencies.Where(x => x.Key.Type == command.Type);
                    aggregateLogicInfo.Dependencies = dependencies.ToImmutableDictionary(x => x.Key, x => (IReadOnlyCollection <ServiceInfo>)x.Value.Select(t => _serviceInfos.Single(s => s.Type == t)).ToImmutableHashSet());
                }
            }

            return(new LogicSchema
            {
                Language = _languageSchema,
                Aggregates = _aggregateLogicInfos.ToImmutableHashSet(),
                Sagas = _sagaInfos.ToImmutableHashSet(),
                Services = _serviceInfos.ToImmutableHashSet()
            });
        }
예제 #3
0
        public AggregateLogicInfo GetAggregate(AggregateEventInfo aggregateEventInfo)
        {
            if (aggregateEventInfo == null)
            {
                throw new ArgumentNullException(nameof(aggregateEventInfo));
            }

            var aggregate = Aggregates.SingleOrDefault(x => x.Events.Contains(aggregateEventInfo));

            if (aggregate == null)
            {
                throw new LogicSchemaException($"No aggregate with event '{aggregateEventInfo.Name}' found in domain logic");
            }

            return(aggregate);
        }