Exemplo n.º 1
0
        private ProjectorInfo ProduceProjectorInfoFromType(AggregateInfo aggregateInfo, AggregateViewInfo aggregateViewInfo, Type projectorType)
        {
            var projectorInfo = new ProjectorInfo(projectorType, aggregateViewInfo, aggregateInfo.IsRoot);

            var eventTypes = projectorInfo.Type.GetTypeInfo().DeclaredMethods
                             .SelectMany(m => m.GetParameters())
                             .Select(p => p.ParameterType)
                             .Where(t => t.GetTypeInfo().IsSubclassOf(typeof(AggregateEvent)))
                             .Distinct();

            projectorInfo.Events = eventTypes.Select(t => _logicSchema.GetAggregateEvent(t)).ToImmutableHashSet();

            return(projectorInfo);
        }
Exemplo n.º 2
0
        public AggregateLogicInfo(Type aggregateLogicType, AggregateInfo aggregateFromLanguage) : base(aggregateLogicType)
        {
            if (!aggregateLogicType.GetTypeInfo().IsSubclassOf(typeof(Aggregate)))
            {
                throw new ArgumentOutOfRangeException(nameof(aggregateLogicType));
            }
            AggregateFromLanguage = aggregateFromLanguage ?? throw new ArgumentNullException(nameof(aggregateFromLanguage));
            if (Id != AggregateFromLanguage.Id)
            {
                throw new LogicSchemaException("Aggregate identifiers from domain language and logic differs");
            }
            Name = AggregateFromLanguage.Name;

            Dependencies = new ReadOnlyDictionary <CommandInfo, IReadOnlyCollection <ServiceInfo> >(new Dictionary <CommandInfo, IReadOnlyCollection <ServiceInfo> >());
        }
Exemplo n.º 3
0
        public AggregateLogicInfo GetAggregate(AggregateInfo aggregateInfo)
        {
            if (aggregateInfo == null)
            {
                throw new ArgumentNullException(nameof(aggregateInfo));
            }

            var aggregate = Aggregates.SingleOrDefault(x => x.AggregateFromLanguage == aggregateInfo);

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

            return(aggregate);
        }
Exemplo n.º 4
0
        private AggregateInfo ProduceAggregateInfoFromType(Type aggregateType)
        {
            var aggregateInfo = new AggregateInfo(aggregateType);

            var nested = aggregateType.GetTypeInfo().DeclaredNestedTypes;

            var commandTypes = nested.Where(x => x.IsSubclassOf(typeof(Command)));

            aggregateInfo.Commands = commandTypes.Select(x => new CommandInfo(x)).ToImmutableHashSet();

            var viewTypes = nested.Where(x => x.IsSubclassOf(typeof(AggregateView)));

            aggregateInfo.Views = viewTypes.Select(x => new AggregateViewInfo(x, aggregateInfo.IsRoot)).ToImmutableHashSet();
            foreach (var viewInfo in aggregateInfo.Views)
            {
                var queryTypes = viewInfo.Type.GetTypeInfo().DeclaredNestedTypes.Where(x => typeof(Query).GetTypeInfo().IsAssignableFrom(x));
                viewInfo.Queries = queryTypes.Select(x => new QueryInfo(x)).ToImmutableHashSet();
            }

            return(aggregateInfo);
        }
Exemplo n.º 5
0
        private AggregateLogicInfo ProduceAggregateLogicInfoFromType(AggregateInfo aggregateInfo, Type aggregateLogicType)
        {
            var aggregateLogicInfo = new AggregateLogicInfo(aggregateLogicType, aggregateInfo);

            var commandHandlersWithDependencies = aggregateLogicInfo.Type.GetTypeInfo().DeclaredMethods
                                                  .Where(m => m.GetParameters().Length > 1)
                                                  .Where(m => m.GetParameters().Any(p => p.ParameterType.GetTypeInfo().IsSubclassOf(typeof(Command))));

            foreach (var handler in commandHandlersWithDependencies)
            {
                var commandParam = handler.GetParameters().Single(p => p.ParameterType.GetTypeInfo().IsSubclassOf(typeof(Command)));
                var commandInfo  = _languageSchema.GetCommand(commandParam.ParameterType);

                var serviceParams = handler.GetParameters().Where(p =>
                {
                    var t = p.ParameterType.GetTypeInfo();
                    if (t.IsArray)
                    {
                        t = t.GetElementType().GetTypeInfo();
                    }
                    return(t.IsSubclassOf(typeof(Service)));
                });
                _dependencies.Add(commandInfo, new List <Type>());
                foreach (var serviceType in serviceParams.Select(p => p.ParameterType))
                {
                    var t = serviceType.IsArray ? serviceType.GetElementType() : serviceType;
                    _dependencies[commandInfo].Add(t);
                }
            }

            var eventTypes = aggregateLogicType.GetTypeInfo().DeclaredNestedTypes.Where(x => x.IsSubclassOf(typeof(AggregateEvent)));

            aggregateLogicInfo.Events = eventTypes.Select(x => new AggregateEventInfo(x)).ToImmutableHashSet();

            return(aggregateLogicInfo);
        }