I am try to learn DDD, so bear with me please. Let say I have an aggregate called Issue. It has a StatusId property. This status can be ie. Open, Closed... and it is stored in a database table called Statuses. (this is because specific user can have specific statuses, so I want the user be able to add new statuses) Now, I have crated a method like this in the Issue aggregate: public static void SubmitIssue(Guid projectId, string issueTitle, string description...)
this method Creates new Issue with the req. params and after that I need to set it into the correct state. But the state is specified in the DB. How to handle this scenario when I must get the data from the DB when doing business logic that must not be couplet do the database access at all? Please help
Your problem is a little more than just a DDD one. It is really about OO design. The problem is that you do not want an enum that will force you to make decisions all over the place. -Littering code with ugly switch and if statements.
There is no easy or precise answer to this.
What I would try to do:
You have Issue class (that can be different types) which means you could inherit and implement concretes based on that type. Important though! If the Issue can change from one type to another, inheritance on the Issue class is the wrong route. In that case you need to move the logical differences of those types (and the business rules they apply) onto the IssueType class, and your Issue class will have to be constructed with the relevant IssueType.
Uncle Bob has a very nice example that is very similar to your problem that he discusses in his book: http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445
Of course he does not speak about the DB in the example, but that is kind of the point of DDD.
I have the PDF version so pages may differ slightly. :Pages 454 to 456 discusses the specific use case.
Really hope this helps somewhat. -almost wish I was working with you on this in a team and could solve it.