protected Component(TAggregateRoot aggregateRoot)
     : this(
         timeSource : aggregateRoot.TimeSource,
         raiseEventThroughParent : aggregateRoot.RaiseEvent,
         appliersRegistrar : aggregateRoot.RegisterEventAppliers(),
         registerEventAppliers : true)
 {
 }
Esempio n. 2
0
        public async Task <TAggregateRoot> GetAsync <TAggregateRoot>()
            where TAggregateRoot : class, IEventStored, new()
        {
            if (_trackedAggregate == null)
            {
                _trackedAggregate = await ExecutionHelper.ExecuteWithRetriesAsync(async ct =>
                {
                    var eventStream = await _stateManager.GetOrAddStateAsync("state", new TEventStream(), ct);
                    var aggregate   = new TAggregateRoot();
                    aggregate.Initialize(_eventController, eventStream.DomainEvents, UtcNowTimeProvider.Instance);
                    return(aggregate);
                }, 3, TimeSpan.FromSeconds(1), CancellationToken.None);
            }

            return((TAggregateRoot)_trackedAggregate);
        }
Esempio n. 3
0
        protected TAggregateRoot CreateAggregateRootInstance <TAggregateRoot>()
            where TAggregateRoot : class, ISourcedAggregateRoot, new()
        {
            TAggregateRoot aggregateTRoot = new TAggregateRoot();

            return(aggregateTRoot);

            //Type aggregateRootType = typeof(TAggregateRoot);
            //ConstructorInfo constructor = aggregateRootType
            //    .GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            //    .Where(p =>
            //    {
            //        var parameters = p.GetParameters();
            //        return parameters == null || parameters.Length == 0;
            //    }).FirstOrDefault();
            //if (constructor != null)
            //    return constructor.Invoke(null) as TAggregateRoot;
            //throw new RepositoryException("At least one parameterless constructor should be defined on the aggregate root type '{0}'.", typeof(TAggregateRoot));
        }
Esempio n. 4
0
        // ReSharper disable UnusedMember.Local
        void RunSerializationRoundtripTestWith <TAggregateRoot>() where TAggregateRoot : AggregateRoot, new()
        {
            var instance = new TAggregateRoot {
                Id = "root_id"
            };

            Console.WriteLine(instance.GetHashCode());

            var firstSerialization        = _sturdylizer.SerializeObject(instance);
            var roundtrippedSerialization = _sturdylizer.SerializeObject(_sturdylizer.DeserializeObject(firstSerialization));

            if (firstSerialization != roundtrippedSerialization)
            {
                throw new AssertionException(string.Format(@"Oh noes!!

{0}

{1}", firstSerialization, roundtrippedSerialization));
            }
        }
        // ReSharper disable UnusedMember.Local
        void RunHashCodeTestWith <TAggregateRoot>() where TAggregateRoot : AggregateRoot, new()
        {
            var instance = new TAggregateRoot {
                Id = "root_id", GlobalSequenceNumberCutoff = 0
            };

            var cache = new InMemorySnapshotCache();

            cache.PutCloneToCache(instance);

            var rootInfo = cache.GetCloneFromCache("root_id", 0);

            Assert.That(rootInfo, Is.Not.Null, "Expected to have found a root in the cache!");

            var frozenInstance = rootInfo;

            cache.PutCloneToCache(frozenInstance);

            Assert.That(frozenInstance.GetHashCode(), Is.EqualTo(instance.GetHashCode()));
        }
Esempio n. 6
0
        public IQueryable <TAggregateRoot> GetModel <TAggregateRoot>() where TAggregateRoot : class, IAggregateRoot
        {
            IEnumerable <XElement> list       = this.xmlContext.Root.Elements(typeof(TAggregateRoot).Name);
            IList <TAggregateRoot> returnList = new List <TAggregateRoot>();

            foreach (var item in list)
            {
                TAggregateRoot entity = null;
                foreach (var member in typeof(TAggregateRoot).GetType()
                         .GetProperties()
                         .Where(i => i.PropertyType.IsValueType ||
                                i.PropertyType == typeof(String)))                    //只找简单类型的属性
                {
                    if (item.Attribute(member.Name) != null)
                    {
                        member.SetValue(entity, Convert.ChangeType(item.Attribute(member.Name).Value, member.PropertyType), null);//动态转换为指定类型
                    }
                }
                returnList.Add(entity);
            }
            return(returnList.AsQueryable());
        }
Esempio n. 7
0
 public static CollectionManager CreateSelfManagingCollection(TAggregateRoot parent)
 => new CollectionManager(parent, parent.RaiseEvent, parent.RegisterEventAppliers());
Esempio n. 8
0
 protected Entity(TAggregateRoot aggregateRoot)
     : this(aggregateRoot.TimeSource, aggregateRoot.RaiseEvent, aggregateRoot.RegisterEventAppliers())
 {
 }
 public new static CollectionManager CreateSelfManagingCollection(TAggregateRoot parent)
 =>
 new CollectionManager(
     parent: parent,
     raiseEventThroughParent: parent.RaiseEvent,
     appliersRegistrar: parent.RegisterEventAppliers());
 protected Entity(TAggregateRoot aggregateRoot) : base(aggregateRoot)
 {
     RegisterEventAppliers()
     .IgnoreUnhandled <TEntityRemovedEventInterface>();
 }