0

Defining domain model is most important task..unfortunately it is one hardest step in DDD. i like to know, how to design a simple domain model from the following statements .

"Every user must have a email to operate the system. the user must be registered using email and password.the administrator / user can initiate the registration process.once user successfully registered the admin must allot a predefined roles to the user, a single user can be assigned to many roles. after the registration process complete ,an email must be sent to the user regarding the credential details along with a welcome message.Every user have one or more key/value paired identifiers called Claims.So the admin able to assign the Claims to single or group of users."

This is may / mayn't look like a business requirement..but if some business expert explains something look like, then how we can shape a domain model from the above statements..can anyone identify the Entities,value objects,domain events,aggregate roots

Note: This question may be an off-topic considering the rules and regulations of stack overflow.instead of blocking /deleting this post ,please suggest me about where i can post it for getting some feedback.

Binson Eldhose
  • 993
  • 3
  • 14
  • 35
  • This looks like a common user-role model. Personally, I think the challenge is how to integrate this bounded context with your core domain. – Yugang Zhou Oct 07 '14 at 23:42
  • @Hippoom,thats what i am confused.this is not a part of business. this is infrastructure required by the application. how i can model the infrastructure requirements in DDD – Binson Eldhose Oct 08 '14 at 05:51
  • The "infrastructure" of your core domain may be another bounded context and may also have its own domain model(considered as a supporting or generic domain from the core domain's perspective). You could adopt anti-corruption-layer or other integration pattern to integrate these bounded contexts. – Yugang Zhou Oct 08 '14 at 06:26
  • @Hippoom,here i can introduce a subsystem called "identity and access management" but my issues to extract the Entities,value objects,domain events,aggregate roots from the statements.. – Binson Eldhose Oct 08 '14 at 06:39
  • Identify the object as an entity if this context cares about its life cycle, for example, User in this case. There is not much information for Role, you could start with entity. You may do some experiments before you finally get a satisfied approach, but it won't do too much side effect to the other part of your system as you separate these model into an individual bounded context. – Yugang Zhou Oct 08 '14 at 07:10

1 Answers1

1

The main purpose of DDD is to model the business rules in an explicit fashion. In your case, I see these rules:

  1. User must have e-mail to register.
  2. Admin must apply role(s) to the user after registration.
  3. User must be notified of credential details with a welcome message.

I can't tell where the Claim object fits into this based on your question.

Here, it sounds like User is the aggregate root since it is what we will be operating on for all three of these requirements, thus you would have a class looking something like this:

public class User  //Aggregate Root (mark this however you like)
{
    public string Email { get; set; }  //value object

    //TODO: Ensure required rule from #1 above
    public void Register(string email) { Email = email; }  

    //Rule #2 above
    public event EventHandler<EventArgs> Registered;  //Domain event - subscriber will probably notify admin of new registered user somehow.
    public void AddRole(Role role) { //Code to add role; }

    //Rule #3 above
    private IEnumerable<Role> Roles { get; }
    //Admin or the process admin uses will call this to notify the user after the role (and maybe claim assignments) are complete.
    public void NotifyAboutRegistration(INotificationProvider provider) 
    {
        string message = "";  //TODO: build string of welcome message with credential details from the description property of the Role type.
        provider.SendWelcomeMessage(message);
    }
}

public struct Role //Value object
{
    public string Name { get; }
    public string Description { get; }
}
Aaron Hawkins
  • 2,611
  • 1
  • 20
  • 24