Example #1
0
        /// <summary>
        /// This method attempts a retrieval on an entity that is contained by the aggregate (and not just direct childs of the aggregate root)
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TEntityId"></typeparam>
        /// <param name="id"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        protected bool TryGetEntity <TEntity, TEntityId>(TEntityId id, out TEntity entity)
            where TEntityId : IId, IEquatable <TEntityId>
            where TEntity : Entity <TEntityId>
        {
            var childContainer = childContainers[id.GetType()] as IDictionary <TEntityId, IPersistThroughEvents>;

            IPersistThroughEvents persistThroughEvents = null;

            childContainer?.TryGetValue(id, out persistThroughEvents);

            entity = persistThroughEvents as TEntity;

            return(entity != null);
        }
Example #2
0
        private IPersistThroughEvents CreateAndSetupRelationships <TChildId, TParentId>(IParcelVisionEventEnvelope <TChildId, TParentId> eventEnvelope,
                                                                                        IPersistThroughEvents entity)
            where TParentId : IId, IEquatable <TParentId>
            where TChildId : IId, IEquatable <TChildId>
        {
            var parent = GetParentOrThrow(eventEnvelope);

            var newChildEntity = (IPersistThroughEvents)Activator.CreateInstance(eventEnvelope.SourceEntityType);
            var parentAsEntity = parent as Entity <TParentId>;

            var childAsHasParent = newChildEntity as IHaveAParent;

            if (childAsHasParent != null)
            {
                SetParentInChild(parentAsEntity, childAsHasParent);
            }

            entity = newChildEntity;
            return(entity);
        }