/// <inheritdoc/>
        public virtual IEnumerable <TEntity> BeforeCreate <TEntity>(IEnumerable <TEntity> entities, ResourcePipeline pipeline) where TEntity : class, IIdentifiable
        {
            if (GetHook(ResourceHook.BeforeCreate, entities, out var container, out var node))
            {
                var affected = new AffectedResources <TEntity>((HashSet <TEntity>)node.UniqueEntities, node.PrincipalsToNextLayer());
                IEnumerable <TEntity> updated = container.BeforeCreate(affected, pipeline);
                node.UpdateUnique(updated);
                node.Reassign(entities);
            }

            FireNestedBeforeUpdateHooks(pipeline, _traversalHelper.CreateNextLayer(node));
            return(entities);
        }
        /// <inheritdoc/>
        public virtual IEnumerable <TEntity> BeforeDelete <TEntity>(IEnumerable <TEntity> entities, ResourcePipeline pipeline) where TEntity : class, IIdentifiable
        {
            if (GetHook(ResourceHook.BeforeDelete, entities, out var container, out var node))
            {
                var targetEntities = LoadDbValues(typeof(TEntity), (IEnumerable <TEntity>)node.UniqueEntities, ResourceHook.BeforeDelete, node.RelationshipsToNextLayer) ?? node.UniqueEntities;
                var affected       = new AffectedResources <TEntity>(targetEntities, node.PrincipalsToNextLayer());

                IEnumerable <TEntity> updated = container.BeforeDelete(affected, pipeline);
                node.UpdateUnique(updated);
                node.Reassign(entities);
            }

            foreach (var entry in node.PrincipalsToNextLayerByType())
            {
                var dependentType   = entry.Key;
                var implicitTargets = entry.Value;
                FireForAffectedImplicits(dependentType, implicitTargets, pipeline);
            }
            return(entities);
        }