Skip to main content
Bounty Ended with Falcon's answer chosen by SiberianGuy
Tweeted twitter.com/#!/StackProgrammer/status/103143995986808832
Bounty Started worth 100 reputation by SiberianGuy
removed abbreviation from title and start of post so people actually know what DDD is
Source Link
Jarrod Nettles
  • 6.1k
  • 2
  • 43
  • 45

DDD Domain-Driven-Design - external dependencies in the Entity problem

I'd like to start DDDDomain-Driven-Design, but there are several problems I'd like to solve before starting :)

Let's imagine I have a Groups and Users and when user wants to join a group, I'm calling groupsService.AddUserToGroup(group, user) method. In DDD I should do group.JoinUser(user), which looks pretty good.

The problem appears if I there are some validation rules for adding a user, or some external tasks need to be started when user is added to the group. Having these tasks will lead to the entity having external dependencies.

An example could be - a restriction that user can only participate in 3 groups max. This will require DB-calls from inside group.JoinUser method to validate this.

But the fact that an Entity depends on some external services/classes doesn't seem so good and "natural" to me.

What's the proper way to deal with this in DDD?

DDD - external dependencies in the Entity problem

I'd like to start DDD, but there are several problems I'd like to solve before starting :)

Let's imagine I have a Groups and Users and when user wants to join a group, I'm calling groupsService.AddUserToGroup(group, user) method. In DDD I should do group.JoinUser(user), which looks pretty good.

The problem appears if I there are some validation rules for adding a user, or some external tasks need to be started when user is added to the group. Having these tasks will lead to the entity having external dependencies.

An example could be - a restriction that user can only participate in 3 groups max. This will require DB-calls from inside group.JoinUser method to validate this.

But the fact that an Entity depends on some external services/classes doesn't seem so good and "natural" to me.

What's the proper way to deal with this in DDD?

Domain-Driven-Design - external dependencies in the Entity problem

I'd like to start Domain-Driven-Design, but there are several problems I'd like to solve before starting :)

Let's imagine I have a Groups and Users and when user wants to join a group, I'm calling groupsService.AddUserToGroup(group, user) method. In DDD I should do group.JoinUser(user), which looks pretty good.

The problem appears if I there are some validation rules for adding a user, or some external tasks need to be started when user is added to the group. Having these tasks will lead to the entity having external dependencies.

An example could be - a restriction that user can only participate in 3 groups max. This will require DB-calls from inside group.JoinUser method to validate this.

But the fact that an Entity depends on some external services/classes doesn't seem so good and "natural" to me.

What's the proper way to deal with this in DDD?

Source Link
Shaddix
  • 491
  • 4
  • 5

DDD - external dependencies in the Entity problem

I'd like to start DDD, but there are several problems I'd like to solve before starting :)

Let's imagine I have a Groups and Users and when user wants to join a group, I'm calling groupsService.AddUserToGroup(group, user) method. In DDD I should do group.JoinUser(user), which looks pretty good.

The problem appears if I there are some validation rules for adding a user, or some external tasks need to be started when user is added to the group. Having these tasks will lead to the entity having external dependencies.

An example could be - a restriction that user can only participate in 3 groups max. This will require DB-calls from inside group.JoinUser method to validate this.

But the fact that an Entity depends on some external services/classes doesn't seem so good and "natural" to me.

What's the proper way to deal with this in DDD?