Example #1
0
        private Action <TAggregate, IAggregateEvent> GetApplyMethod(Type aggregateEventType)
        {
            var aggregateType  = GetType();
            var typeDictionary = ApplyMethods.GetOrAdd(
                aggregateType,
                t => new ConcurrentDictionary <Type, Action <TAggregate, IAggregateEvent> >());

            var applyMethod = typeDictionary.GetOrAdd(
                aggregateEventType,
                t =>
            {
                var m = aggregateType.GetMethod("Apply", new [] { t });
                if (m == null)
                {
                    throw WrongImplementationException.With(
                        HelpLinkType.Aggregates,
                        "Aggregate type '{0}' doesn't implement an 'Apply' method for the event '{1}'. Implement IEmit<{1}>",
                        GetType().Name,
                        t.Name);
                }
                return((a, e) => m.Invoke(a, new object[] { e }));
            });

            return(applyMethod);
        }
Example #2
0
        protected AggregateRoot(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            if (!id.Trim().Equals(id))
            {
                throw new ArgumentException(
                          string.Format(
                              "Aggregate IDs should not contain leading and/or spaces as this does '{0}' for aggregate {1}",
                              id,
                              typeof(TAggregate).Name),
                          "id");
            }
            if (id.Length > 255)
            {
                throw new ArgumentException(string.Format(
                                                "Aggregate IDs must not exceed 255 in length and '{0}' is too long with a length of {1}", id, id.Length),
                                            "id");
            }
            if ((this as TAggregate) == null)
            {
                throw WrongImplementationException.With(
                          HelpLinkType.Aggregates,
                          "Aggregate '{0}' specifies '{1}' as generic argument, it should be its own type",
                          GetType().Name,
                          typeof(TAggregate).Name);
            }

            Id = id;
        }
Example #3
0
        protected AggregateRoot(TIdentity id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if ((this as TAggregate) == null)
            {
                throw WrongImplementationException.With(
                          HelpLinkType.Aggregates,
                          "Aggregate '{0}' specifies '{1}' as generic argument, it should be its own type",
                          GetType().Name,
                          typeof(TAggregate).Name);
            }

            Id = id;
        }