I am trying to understand how entities operate in multiple bounded contexts.
Given an Employee of a Company. In (for example) the Human Resources context, this person has a name, surname, address, salary reference number, and bank account. But in the Accounting context all that is relevant is the salary reference number and bank account.
Do you have an Employee entity in the HR context and a Value-Type (e.g. SalariedEmployee
) in the Accounting context?
class Employee
{
public BankAccount BankAcountDetails { get; set; }
public string FullName { get; set; }
public Address ResidentialAddress { get; set; }
public string SalaryRef { get; set; }
}
SalariedEmployee
class (??) : Employee's value-type
class SalariedEmployee
{
public SalariedEmployee(string salaryRef, BankAccount bankAcountDetails)
{
...
}
public string SalaryRef { get; }
public BankAccount BankAcountDetails { get; }
}
Does the HRService in the bounded context return this information? Or do you use the Employee class in both contexts?
A bounded context is simply the boundary within a domain where a particular domain model applies. Looking at the previous diagram, we can group functionality according to whether various functions will share a single domain model. Bounded contexts are not necessarily isolated from one another.
In domain-driven design, an entity is a representation of an object in the domain. It is defined by its identity, rather than its attributes. It encapsulates the state of that object through its attributes, including the aggregation of other entities, and it defines any operations that might be performed on the entity.
Anything that shows domain concepts, relationships, rules, and so on. Since a bounded context is a boundary for a model, it could include concepts from multiple subdomains. Or a single subdomain could be modelled as multiple bounded contexts.
From http://msdn.microsoft.com/en-us/library/jj554200.aspx :
Bounded contexts are autonomous components, with their own domain models and their own ubiquitous language. They should not have any dependencies on each other at run time and should be capable of running in isolation.However they are a part of the same overall system and do need to exchange data with one another.
If you are implementing the CQRS pattern in a bounded context, you should use events for this type of communication: your bounded context can respond to events that are raised outside of the bounded context, and your bounded context can publish events that other bounded contexts may subscribe to. Events (one-way, asynchronous messages that publish information about something that has already happened), enable you to maintain the loose coupling between your bounded contexts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With