private void Initialize(SavePersonInputDto organization, EntityDependency[] dependencies)
        {
            RegisterCommandRepositoryFactory <Person>(() => new PersonCommandRepository());

            RootEntity = new Person
            {
                Id   = organization.PersonId,
                Name = organization.Name
            };

            Enqueue(new SaveEntityCommandOperation <Person>(RootEntity, dependencies));

            Enqueue(new DeleteLinksCommandOperation <Person>(RootEntity, "UnlinkPhonesFromPerson"));

            if (organization.Phones?.Any() == true)
            {
                foreach (var dto in organization.Phones)
                {
                    ILinkedAggregateCommandOperation operation;

                    if (dto is SavePhoneInputDto)
                    {
                        operation = new AddLinkedAggregateCommandOperation <Person, SavePhoneCommandAggregate, SavePhoneInputDto>(
                            RootEntity,
                            (SavePhoneInputDto)dto,
                            new EntityDependency[]
                        {
                            new EntityDependency
                            {
                                Entity   = RootEntity,
                                Selector = "Phones"
                            }
                        }
                            );

                        Enqueue(operation);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }

            Enqueue(new DeleteLinksCommandOperation <Person>(RootEntity, "UnlinkAddressFromPerson"));

            if (organization.Address != null)
            {
                ILinkedAggregateCommandOperation operation;

                var address = organization.Address;

                if (address is SaveAddressInputDto)
                {
                    operation = new AddLinkedAggregateCommandOperation <Person, SaveAddressCommandAggregate, SaveAddressInputDto>(
                        RootEntity,
                        (SaveAddressInputDto)address,
                        new EntityDependency[]
                    {
                        new EntityDependency
                        {
                            Entity   = RootEntity,
                            Selector = "Address"
                        }
                    }
                        );

                    Enqueue(operation);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
 public SavePersonCommandAggregate(SavePersonInputDto organization, EntityDependency[] dependencies = null) : base(new DomainFramework.DataAccess.RepositoryContext(OrganizationPersonWithCommonEntitiesConnectionClass.GetConnectionName()))
 {
     Initialize(organization, dependencies);
 }