BACKGROUND: I have a Person domain object. This is the cumulative root. I have included the part below.
I expose methods for executing the behavior of objects. For example, to add BankAccount, I have the AddBankAccount () method. I did not include all the methods of the class, but suffice it to say that any public property must be updated using the method.
I am going to create an IPerson repository to handle CRUD operations.
public interface IPersonRepository { void Save(Person p);
QUESTION How do I tell the repository which fields need to be updated when updating an existing person? For example, if I add a bank account to an existing person, how can I transfer this information to the repository when the repository. Called ()?
It is easy to determine in the repository when a new person is created, but when an existing person exists and you update the fields of this person, I am not sure how to report this to the repository.
I do not want to pollute my Person object with information about which fields are updated.
I could have separate methods in the repository, such as .UpdateEmail (), AddBankAccount (), but this is like brute force. I need a simple .Save () method in the repository and it determines what needs to be updated somehow.
How did others deal with this situation?
I searched the web and stackoverflow but didn't find anything. I shouldn't be looking right, because it seems like something simple when it comes to persistence in the DDD paradigm. I could also be aloof from understanding DDD :-)
public class Person : DomainObject { public Person(int Id, string FirstName, string LastName, string Name, string Email) { this.Id = Id; this.CreditCards = new List<CreditCard>(); this.BankAccounts = new List<BankAccount>(); this.PhoneNumbers = new List<PhoneNumber>(); this.Sponsorships = new List<Sponsorship>(); } public string FirstName { get; private set; } public string LastName { get; private set; } public string Name{ get; private set; } public string Email { get; private set; } public string LoginName { get; private set; } public ICollection<CreditCard> CreditCards { get; private set; } public ICollection<BankAccount> BankAccounts { get; private set; } public ICollection<PhoneNumber> PhoneNumbers { get; private set; } public void AddBankAccount(BankAccount accountToAdd, IBankAccountValidator bankAccountValidator) { bankAccountValidator.Validate(accountToAdd); this.BankAccounts.Add(accountToAdd); } public void AddCreditCard(CreditCard creditCardToAdd, ICreditCardValidator ccValidator) { ccValidator.Validate(creditCardToAdd); this.CreditCards.Add(creditCardToAdd); } public void UpdateEmail(string NewEmail) { this.Email = NewEmail; }