Aggregate root, factory method and entity as a result

Dariusz Lenartowicz <[email protected]>
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <[email protected]>
Hi,
I'm looking for some advice.

Suppouse I have Tenant AR which can create User entity (User is not AR 
within this particular context), so code can looks like this:

     var tenantId = sessionContextService.TenantId;
     var tenant = tenantRepo.Get(tenantId);
     var user = tenant.CreateUser(username, password); // there I can 
validate invariants
     userRepo.Add(user);

To achive this User class should have public ctor:

     public User(Tenant tenant, string username, string password)

but nobody prevent me to do this:

     var tenantId = sessionContextService.TenantId;
     var tenant = tenantRepo.Get(tenantId);
     var user = new User(tenant, username, password);
     userRepo.Add(user);

How to force creation of User entity through CreateUser method on tenant 
AR?
Is it only matter of discipline or there are some solutions for that 
situations?

Best regards
Darek




------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/domaindrivendesign/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/domaindrivendesign/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/us/yahoo/utos/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.