Domain driven design Domain Design Question

I am working on an application where I can have Teacher, Student etc role. Some of the functionality is similar so I also have a base class User. User contains AddRole method and other stuff. Now, I want that when the Teacher object is created the "Teacher" role is automatically assigned to the object. I am doing this inside the constructor but I think it is ugly. Here is the code: public class Teacher : User { public Teacher() { AddRole(new Role() { RoleName

Domain driven design DDD: Getting aggregate roots for other aggregates

I've been studying DDD for the past 2 weeks, and one of the things that really stuck out to me was how aggregate roots can contain other aggregate roots. Aggregate roots are retrieved from the repository, but if a root contains another root, does the repository have a reference to the other repository and asks it to build the subroot?

Domain driven design Why not split the data access layer into two?

Everywhere I look, I noticed that both Domain Driven Design (DDD) and entity hydration approaches attempt to populate entities directly from the data layer. I disagree with such approaches. It is not because these approaches do not work because these do. Instead, I would argue that such approaches give a low level of transparency for testing purposes. I propose that at the data access layer, data is retrieved to populate dictionaries instead of the directly populating the entities themselves. Th

Domain driven design Address dilemma

I have Person aggregate in which Address is part and vo , but now i have another aggregate Payment which have another VO PaymentInfo , which contains details like Creditacard number and other details, but now i need Billing Address and Shipping Address in PaymentInfo VO. Now since Address is integral to Person i cannot use that. So what i do , Create separate Address Vo in Payment aggregate and use it as billing address and Shipping Address. Move address in to separate aggregate and referenc

Domain driven design DDD and batch processing (e.g. using Spring batch)

I would like to use Spring batch for a batch application. I already have a domain model designed following DDD. My question is how batch processing (in my case, using Spring batch) fits with DDD? For example, I have an aggregate root A and one of its children is the entity B. A has a list of one or more Bs. The batch application receives a file when each line corresponds to an operation (add, delete...) on the list of Bs. In my aggregate root A, I have one method for each operation (e.g. addB,

Domain driven design Domain driven design: Domain rules in services and aggregates

I have doubts about the way the domain should enforce business rules when there is more than one aggregate involved. Suppose I have the account and external account aggregates: public class Account { public String getId() {...} public void add (Double amount) {} } public class ExternalAccount { public String getId() {...} public void add (Double amount) {} } and this service: public class TransferService implements TransferServiceInterface { public void transfer (String

Domain driven design Extensibiliy with DDD: Module Vs Bounded Context in DDD with MEF

Eric in his book touches the subject of Modules very little. He also does not talk about the relation of the structure of modules to bounded contexts with examples. Do Bounded Contexts contain modules or modules contain the Bounded Contexts? When an application has DDD, how easy it can be extendable? The structure of the application is very important when we design Extensible applications. The Microsoft MEF framework can auto-discover modules/components from a dll. Let us take an example. In a

Domain driven design Modelling a recursive stock system with non-

I'm trying to model a business domain that produces stock that actually has a complex recursive stock system. Stock can be uniquely labeled at the item level, or; Stock can be uniquely labeled at the box level (containing a number of un-identifyable items), or; Stock can be labelled at the pallet level (containing a number of un-identifyable boxes), or; Stock can be labelled uniquely and then contained within levels above, i.e. unique items in a unique box. Or unique items directly placed on a

Domain driven design DDD - Aggregate Root load/query performance

I'm playing with DDD and this question pop up. How I load child Aggregate Roots? Several performance issues would arise. Imagine the following example: public AggregateRoot1 { #region properties #endregion public AggregateRoot2 AR2{get;set;} public IEnumerable<AggregateRoot3> AR3List{get;set;} (...) } If I load AggregateRoot2 and AggregateRoot3 list when I get AggregateRoot1, the graph would me massive. This not seem a nice approach. I have two optio

Domain driven design Where i need to place code related to storing a entity in a domain driven design

I am trying to design a application using domain driven design, i have a doubt regarding storage of an entity data. First i am creating an entity and applying business rules on the entity. Finally i want to store this data. I am using repository pattern to abstract the database operations. Now where i need to place code related to saving the entity data to database. Is it goes in the entity? or a domain service?

Domain driven design ddd - Is my ValueObject implementation correct?

I am trying my best to create a web app to familiarize myself with DDD and ValueObjects. So far everything is working fine, I am just asking myself if I am correctly implementing my value objects. Here is my current state (code stripped from non-essential parts): class User { private $id; /** * @var Credentials */ public $credentials; public function getId() { return $this->id; } } class Credentials { private $username; private $password; public functio

Domain driven design Event validation

We are considering implementing CQRS pattern at work and have a couple of questions about validation. Let's say we have 3 aggregate roots: User Business UserToBusinessRelationship When user signs up the events sent would be: UserCreated BusinessCreated UserAddedToBusiness Events need to be validated, for example to create a link between a user and a business both user and business should be created. I see two approaches. Upfront validation: construct read model on the fly using las

Domain driven design Should entity have methods and if so how to prevent them from being called outside aggregate

So, if there is an entity within an aggregate what is the best/usual way to prevent outside world from doing something like Aggregate.Entity.SomeMethod()? (in case there is a getter for an entity on aggregate) Should aggregate expose entity at all or should its getter always give a value object representation of entity? (actually a copy to break a direct reference) Or, on the other hand, should entity be anemic and all its methods moved to aggregate?

Domain driven design A series of simple Aggregate Root questions (Domain Driven Design)

I have a few (hopefully) simple questions about aggregate roots in domain driven design: Is it okay to have an aggregate root as a property of another aggregate root? Is it okay to have a given entity inside two or more aggregate roots? My final question is a bit more involved. I have a website that has a few entities that really belong to a "website" aggregate root. They are 'News', 'Products', and 'Users'. There isn't a 'Website' table in the database, but a 'Website' seems like a good agg

Domain driven design Root aggregate problem in domain driven design

I have two Entities Publisher and SocialAccount , both are independent and having relationship of Many to Many. Both are root Aggregates , now i cannot get social account through Publisher and I want to convert M To M relationship to 1 To M. So I Introduced another entity Registration , will have {PubID, SocID, CreateDate}. Now there is 1 To M relationship between Publisher and Registration and 1 to 1 between Registration and SocialAccount. so publisher will have List <Registrations>

Domain driven design Domain Driven Design: Repository per aggregate root?

I'm trying to figure out how to accomplish the following: User can have many Websites What I need to do before adding a new website to a user, is to take the website URL and pass it to a method which will check whether the Website already exist in the database (another User has the same website associated), or whether to create a new record. <= The reason for this is whether to create a new thumbnail or use an existing. The problem is that the repository should be per aggregate root, whic

Domain driven design Domain driven design: allowed logic in application services

I have a question of how to better organize the implementation of the following functionality. Suppose a user needs to be registered into the system by unique email and password (first step) and then he should confirm registration (second step). I have several choices of structuring implementation of first step (registration) between application services/domain services/user entity and I'm not sure which one is better. First option: AppService: var existingUser = UserRepository.GetUserByEmail

Domain driven design Eventual consistency across aggregate roots in the same bounded context using a process manager aka saga

Suppose you've got two aggregates in your bounded context which have some constraints amongst each other. Using DDD these inter aggregate constraints can't be enforced in the same transaction i.e. the aggregate boundaries are transactional boundaries. Would you consider using what in the Microsoft CQRS journey is called a "process manager" to coordinate two aggregates in the same bounded context or is a process manager only used to coordinate between two bounded contexts? What would the equival

Domain driven design DDD Fetching List of Roots

So, I've got a WCF service that accepts commands and maps them to calls into the domain services layer. When doing write type of commands to the domain, this pattern is nearly perfect. What I'm wondering is how everyone is doing reads, more specifically, getting lists of aggregates from the model for display. As I stated, I have a WCF service that calls into the service layer. Currently, I have a method on my service that returns a list of aggregate roots. Somehow, this feels a bit dirty.

Domain driven design Translator between bounded contexts in DDD (and some other questions)

I've been reading Eric Evans' DDD: Tackling Complexity in the Heart of the Software and in the section in context maps, Evans cited an example of 2 bounded contexts (Booking context and Network Traversal Service) using a translator to integrate them. If I understand correctly, when we create a model, we put everything into bounded contexts creating conceptual boundaries for the domain. My questions are: If everything should be in a bounded context, where should the translator be located? In E

Domain driven design PHP How should Repositories handle adding/removing/saving/deleting entities?

I am having a bit of trouble implementing the Repository pattern, due to some confusion. As far as I can tell now, a Repository should behave like an in-memory collection of objects, so if I do say: $users = new UserRepository(new UserMapper); $users->findAll(); The Users repository will load and return an array of User entities. Now I can either use them for just reading data, or can update the data on any particular entity, and invoke a save() method on the Repository that will utilize

Domain driven design CQRS + Event Sourcing without DDD

I'm building a system thats very data centric. I have large hierarchical datasets but no business rules. The output of the system comes from some calculations done on the data and a number of reports. I need to have a complete audit trail (for regulatory reasons) and be able to run the calculations against a dataset from any point in it's past. For these reasons I thought having an event sourced system using CQRS was the way to go. All the examples I've seen revolve around creating aggregat

Domain driven design Multiple Data Transfer Objects for same domain model

How do you solve a situation when you have multiple representations of same object, depending on a view? For example, lets say you have a book store. Within a book store, you have 2 main representations of Books: In Lists (search results, browse by category, author, etc...): This is a compact representation that might have some aggregates like for example NumberOfAuthors and NumberOfRwviews. Each Author and Review are entities themselves saved in db. DetailsView: here you wouldn't have aggreg

Domain driven design Can an Aggregate Root factory method return a command instead of publishing an event?

In Vaughn Vernon's Implementing Domain-Driven Design book, he described the use of factory method in an Aggregate Root. One example was that of a Forum aggregate root which had startDiscussion factory method which returned a Discussion aggregate root. public class Forum extends Entity { ... public Discussion startDiscussion( DiscussionId aDiscussionId, Author anAuthor, String aSubject) { if (this.isClosed()) { throw new IllegalStateException("Forum is clos

Domain driven design Domain Driven Design Precise Aggregate Definition

Aggregate An Aggregate is a group of associated objects which are considered as one unit with regard to data changes. The Aggregate is demarcated by a boundary which separates the objects inside from those outside. Each Aggregate has one root. The root is an Entity, and it is the only object accessible from outside. In reading the book DDD Quickly, this was the proposed definition of aggregate. However, as I was parsing through some videos on youtube, specifically: DDD & REST - Domain Dr

Domain driven design Should aggregate model contain metadata?

I would like to clarify, how the model of an aggregate should look like. I have couple of events, which contains data which won't be ever used for validation. For example, metadata like user_id who triggered the action (auditing), correlation_id (observability), labels / flags. They will be received within the command and will be sent out as the property of the event. It won't be lost as each event is persisted. That's clear. But should the aggregate object contain these values? Projection wi

Domain driven design Where should I check for uniqueness in a ddd architecture

In my domain model I have a customer aggregate root. My business rule is -> I can not add a new customer with the same firstname, lastname and email address. Where is the best place for this kind of validation check? First from my point of view its completely wrong to place this kind of check inside of my customer aggregate. Second it also feels unnatural to add this validation inside of my CustomerRepository as I want to treat them just as simple in memory collections with mainly the same logi

Domain driven design Apply the same operation to multiple aggregates

I have a StockLine aggregate. It shows what product resides on which location in a warehouse and in which quantity. Now on UI I am able to select one stock line and reserve some quantity. Later on we need to implement multiselect of the stocklines and reserve them. Lets say I selected 2 aggregates, and I want to reserve both of them. What is the best way of doing this, taking in consideration that I already have implemented a usecase to reserve 1 aggregate. 1) foreach selected aggregate call Bac

Domain driven design DDD - bounded contexts sharing/communication

I am trying to utilize some DDD approaches in the app that allows guest purchase. While it looks easy, I got a bit confused and asking for your DDD advice. The app has several bounded contexts and we are looking at 3 of them: Customers (customers manage their user settings here, authentication, also admin can potentially create users) Sales (orders) Billing (charging customers for one-off payments and subscriptions) The user story: As a guest I want to order the product to do somethin

Domain driven design CQRS and CRUD screens

One of the basic tenets of CQRS, as I understand it, is that commands should be behaviour-centric, and have a value in the business or the UL, and not data-centric, ie., CRUD. Instead of focusing on updating a customer, we have commands like CustomerHasMoved. What if you have CRUD screens which are there to correct certain data. For example, we need to change the name of a customer which is misspelled. This doesn't really have much value in the business. Should this just be under the umbrella of

Domain driven design Real-World DDD: Structuring the Domain Layer

I am trying to make the jump from data-centric design and development into DDD and have read Evans and Nillson but am still having trouble wrapping my head around how I should structure my Domain Layer. I'm sure the nature of my current project isn't helping! A little background The application is an internal solution to manage personnel assessments. HR personnel will create assessment "templates" that consist of a set of questions that team leads and managers are to complete for each of thei

Domain driven design RavenDB Domain Model

I'm building my first small RavenDB application and I'm wondering if I'm approaching things correctly when building my domain model. I've got a list of countries which I want to use in multiple places in my model. Typically in the past I would have created a database table to store the countries and a country object which looked a little like this: public class Country{ public int Id {get;set;} public string CountryName {get;set;} } When I went to use the country class I would have h

Domain driven design Why do sagas (aka, process managers) contain an internal state and why are they persisted to the event store?

A lot of articles on CQRS imply that sagas have an internal state and must be saved to the event store. I don't see why this is necessary. For example, say I have three aggregates: Order, Invoice and Shipment. When a customer places an order, the order process starts. However, the shipment cannot be sent until the invoice has been paid and the shipment has first been prepared. A customer places an order with the PlaceOrder command. The OrderCommandHandler calls OrderRepository::placeOrder().

Domain driven design Event Sourcing and optimistic concurrency control

When you want code works under race conditions, commonly developers uses Optimistic concurrency control (OCC). From Wikipedia: ...before committing, each transaction verifies that no other transaction has modified the data it has read. If the check reveals conflicting modifications, the committing transaction rolls back... An approach to implement OCC is checking a version of the data to be modified. If the version differs, then other transactions have modified the data and the it's up

Domain driven design Which is aggregate root. Recipient or Cost ? DDD

I'm creating an application to analyze my expenses. I want to implement in a DDD way. My 2 main entities are : CounterPart(Recipient/Sender) and Expense(Cost/Income) class diagram It seems logical to take CounterPart as an aggregate root but I need to do a lot of actions on Expense directly like marking it as a daily, monthly, ... expense. Can I only interact on expense using the counterPart ?

Domain driven design DDD correct the identity of an Entity

In DDD, Entities have a value that uniquely identify them i.e. the identity. Sometimes this identity is generated by the server, sometimes is obtained from another BC, sometimes is provided by the user, and so on. Let's assume we are working in the scenario where the user provides the identity. Let's pretend that there is a business process exclusively done on paper and not-to-be-migrated-to-computer-soon where the Process Owner decides the new name for a thing called a Resource. The name is alw

Domain driven design DDD: Where to keep domain Interfaces, the Infrastructure?

Does it make sense to group all Interfaces of your Domain Layer (Modules, Models, Entities, Domain Services, etc) all within the Infrastructure layer? If not, does it make sense to create a "shared" project/component that groups all of these into a shared library? After all, the definition of "Infrastructure Layer" includes "shared libraries for Domain, Application, and UI layers". I am thinking of designing my codebase around the DDD layers: UI, Application, Domain, Infrastructure. This wo

Domain driven design Domain Driven Design - Entities VO's and Class Hierarchy

The shorter version of the Question: "Is it ok to have a superclass, with 2 subclasses, one is an entity the other is a Value Object?" To longer version: T have a Team superclass. The Team has the Master, Helpers and a Code. Then i have the DefaultTeam, subclass of Team, which is an entity with an unique **Code**** has its domain identity. Then i have the **ExecutionTeam, its a subclass of Team and has an extra attribute OriginalTeam: public abstract class Team{ public string Code{ get;

Domain driven design Simple (CRC-style) domain design / modelling tool

I thought this would be easy.... For a new project about to start, I'm looking for a simple Windows-based tool for domain-driven modeling - something like "digital CRC's" (Collaboration Responsibility Cards) that would allow me to easily: define the entities involved define their properties (and metadata about those properties) define the links between those entities I would love to have something that's "dynamic", e.g. if I view the Customer entity, I would like to be able to click on the

Domain driven design How to avoid holding reference to non-root-aggregate in another non-root-aggregate?

In many ddd examples we have a simple: Order (aggregate root [AR]) and OrderLine (aggregate member [AM]) + Invoice (aggregate root [AR]) and InvoiceLine (aggregate member [AM]) In that examples we issue an invoice on order so it is direct reference from one AR (Invoice) to another (Order) which is clearly correct. However, in my case things are more complicated: We issue an Invoice on many OrderLines from different Orders. So on one Invoice, we have: InvoiceLine #1 referencing to Order

Domain driven design CQRS/ES denormalizers

I'm working on an invoicing web application which uses event sourcing and CQRS. I have 2 denormalizers for different queries (one for a list of invoice summaries, and one for a single invoice with full details). I find it strange I need to copy a lot of the logic for these 2 denormalizers - for example, listen to events that change the total, subtotal, taxes etc. I ended up passing the aggregate itself, which contains the real calculated data, on the messaging bus instead of just the events an

Domain driven design How to model associations in DDD approach?

I'm learning DDD approach step by step with imaginary business domain by reading books of Eric Evans and Vaughn Vernon and I try to implement it using in my project using PHP (but it really doesn't matter here). Recently I've been reading a lot of Aggregate, AggregateRoot and Entity patterns for models that should be defined by a domain. And, frankly, I'm not sure I understand all definitions well so I decided to ask my questions here. At first I'd like to present my (sub)domain responsible fo

Domain driven design DDD: using infrastructure from application service without creating abstraction in domain?

I'm following domain driven design in a new project. I need to validate some data that I'm receiving in my application service. To validate that data I need to make an http request to a third part endpoint. Following DDD, I have implemented that request in Infrastructure layer. The problem I have now is that I don't want to create an abstraction for that implementation in the domain layer because it has nothing to do with any entity or domain logic, it's purpouse consists only to validate the da

  1    2   3   4   5   6  ... 下一页 最后一页 共 8 页