Re: Aggregate root, factory method and entity as a result

Chris Bingham <[email protected]>
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <CAKESE8t6hmRxn58Srfa7A4c5a02jSy=n8b+G62iT++n-Hu7uqA@mail.gmail.com>
Use a typed state machine?

Make the constructor of user require an instance of 'RegisteredTennant' or
whatever the your domain names the required state?

Otoh, why expose the user at all? It looks like adding a user is part of
the Tennant aggregates consistency boundary, so ideally I think you'd keep
it as a property/reference on the Tennant itself rather than saving it to a
separate repository?
On 7 Mar 2014 22:30, "Dariusz Lenartowicz" <[email protected]>
wrote:

>
>
> 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
>
>  
>
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.