We had a long conversation in DDD/CRQS mailing list a couple of months ago (link). One part of the discussion was "one way command" and this is what I think you are assuming. You can find out that Greg Young is opposed to this pattern. A command changes the state...

Since these two classes are in separate namespaces, you could keep to the same name. But as you mentioned, this can get ugly and is certainly misleading. I strongly advocate for pure, "real-world" naming in your domain layer. Account is a great example. Your rich Account domain entity, with its...

The comments from @plalx pointed me in the right direction. I'm posting my resolution here as the answer to help others who might have this same type of question. After reading a couple of really good articles by Vernon about modeling aggregates (you can find the articles here and here)...

The only way I managed to move forward (using the private field) was to set a global Access.Field convention. .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Customer>() .Conventions.Add(DefaultAccess.Field()))...

Absolutely, validation is the process of approving a given object state, while invariant enforcement happens before that state has even been reached. A corollary is that invariant enforcement is best performed by the thing that is being mutated (or created) itself, like a self-protection reflex, whereas validation is usually done...

Problem 1 I think you need to do some transactional analysis in addition to the business analysis here. If your domain is highly collaborative (which is what DDD is recommended for), how often do moves to a given compartment happen ? Would it be feasible contention-wise for the Move operation...

Passing array of values on the constructor is not a good idea. If the required data is not present in the array. your domain entity will be in invalid state. Just put the required fields individually on the constructor, that way it is more readable and the required fields are...

It sounds to me like you have chosen the same domain objects on the write side as you have on the read side. You do not have to do a one to one mapping between these models. You can create different read models from the same domain object depending on...

First of all, I have to agree with plalx's last paragraph regarding the need to synchronise the hidden flags in both Post as well as Comment. One would assume that the UI would look at a Post and realise it's hidden and not bother fetching/showing the comments? But I appreciate...

Declared bias: I am the products manager of the open source Naked Objects framework. (Also, both your posting and my response might get criticised for being an unsuitable topic - request for product advice - for Stack Overflow. But meantime ...) Yes, I absolutely think Naked Objects would be suitable...

should I load all users collection in Club to add new and save? No, you can add a new User to Club.Members and EF will save the new user. It's not necessary to load the users first. What is the best way for modeling entities with big collections That...

Since CQRS means that Queries are separated from Commands, you may not be able to perform a Query right away, because the Command may not yet have been applied (perhaps it never will). In order to reconcile that with HATEOAS, instead of returning 200 OK from the POST request, the...

From the implementation point of view. You may write the code as: var assistant = GetAssistant(Id); var therapist = GetTherapist("[email protected]"); therapist.ManagedBy(assistant); repository.Save(therapist); The therapist knows if he/she is managed by an assistant, so the rule is applied here. And the therapist can handle concurrency contention with locks. On the other...

What the author (Dino Esposito) is missing in his book is the clear separation of concerns that CQRS brings. If I'm not mistaking, this pattern is completely missing from his book. In Esposito's latest MSDN article, he explains CQRS, so I think he just wasn't that experienced at the time...

I would probably have the subscriber to the message queue fire a domain event that contains the data received from the other bounded context. An event handler for this event will then create the relevant Entity for this context. In case where it is needed, I can potentially fire another...

Try to look at your whole domain from different perspectives, as an editor of article, you probably will use sentences like creating a draft of an article, publishing an article, as an article a reader you will in example read article and comment on it. Alongside building your domain language...

I usually don't do that. Normally, these information comes from the client which was loaded before (it existed). However, there are cases that the CustomerId is missing at the time you update your db. Due to concurrency when many users access the system at the same time. But this case...

Vaughn Vernon writes about Persisting Value Objects (page 248) in his excellent book Implementing Domain-Driven Design. ORM and Single Value Objects The basic idea is to store each of the attributes of the Value in separate columns of the row where its parent Entity is stored. Said another way, a...

I think when you expect one user to be a member of 10s of thousands of groups, the model you have chosen is wrong. You need to remove the list of groups from the user document and stick to the relational model, only keeping group ids. Imagine your groups will...

The first thing to note is that DDD is not an architectural pattern, though you can use architectures that conform to the DDD methodology. As for two classes in different domains (bounded contexts?), if it's a trivial code I would just duplicate it, otherwise you could put it into the...

Lately I favor returning events from domain methods and handling those in the application service layer. Since the application service layer is where you bring together all kinds of infrastructure further processing of the returned events, such as dispatching, can be handled in the application service layer. In this way...

First always make sure that your domain services are stateless. The usual roles of domain services is stuff like validation and persistence. In those cases simply create mocks/stubs/dummies of infrastructure services that they use, pass them in, inside a unit test and assert certain behavior on those mocks. Business as...

Sounds like you may be doing a bit too much in your command handler. Just to be clear - the role of the command handler is to receive the command, load the appropriate aggregate and to send the command into the aggregate. Finally it grabs any events the aggregate may...

I would take the second approach, but with one important change. I would instead create a value object called PurchasedDeal, that consists of just a DealID and Quantity field. The User aggregate could instead load a collection of this more lightweight purchase history object. Performance should be good with this...

You're right with wanting to use GUIDs as IDs. If your UI tools do not support GUID ids, use another tool. I'd say that using vendor-specific UI tools is counter to the spirit of ASP.NET MVC anyway. You should be able to find something free and open source which does...

Absolutely. In my experience, transactional analysis is a better design counsellor than any kind of "X cannot exist without Y" rule. If there's a lot of contention at stake, definitely try to identify and extract subparts of an aggregate that are more frequently accessed or independently accessed, and make them...

In the rare, specific case that you need to process commands serially, in a first-in/first-out manner, a queue is a simple way to accomplish this. Outside of that, I see no real benefit to using an in-memory queue for processing commands. In a SOA scenario, using queuing technology (MSMQ, RabbitMQ,...

The whole point of having a BC is to keeps things separated. BC1 and BC2 are strangers. If they share the language they should be one BC. Neither BC needs to know "little" or more about the other. Also querying another BC is just asking for trouble later. Both BC...

As you pointed out, value objects are not entities, and thus shouldn't be directly retreived from a repository. They are, however, aspects/properties of an entity. When you wish to reference all Categories of the Catalog, you are, in principle, performing a query against the Catalog; which Categories do you contain?...

It makes sense to do authorization in any methods that need authorization otherwise there will be a security problem, especially when these methods are entry points in your backend logic. That means if you deploy these domain services as another tier which is accessible from outside, these methods really need...

DDD and SOA play well together. Usually service boundaries match with your bounded contexts. You design cross-context communication using SOA and it all works. EA does not go deep into how you develop your "services" inside but DDD helps you there.

You try to register ApplicationUserCreatedEventHandler as an open type of IHandler<> but this type is not a IHandler<> it is a IHandler<ApplicationUserCreatedEvent> so you have to register it as it. builder.RegisterType<ApplicationUserCreatedEventHandler>() .As(typeof(IHandler<ApplicationUserCreatedEvent>)); And you will be able to resolve it this way : container.Resolve<IEnumerable<IHandler<ApplicationUserCreatedEvent>>>(); By the way, if you want...

Objects are made Serializable to be able to be transferred. It allows to convert Object to bytes and then bytes to Object. Note that usually DTO are made lighter (since travelling to client) than your Domain Objects that usually have a lot of attributes made for Business processing only. So...

I would even say it is recommended since in your command handler you most probably will want to reply back to the originator with the processing status and the only way to do this is to engage the bus reply/response functionality. As it was discussed in the DDD/CRQS Google group,...

Since you have the concept of Bounded Context, you should not share domains between the namespaces. Actually, you should have one Item for each namespace that requires it, and each of those Item should have it's own fields as required by the context it is included. As Eric Evans said,...

For a system-wide password expiration policy your approach is not that bad, as long as your UserPasswordService is a domain service, not an application service. Embedding the password expiration policy within User would be a violation of the SRP IMHO, which is not much better. You could also consider something...

For these types of things you can use the null object pattern. Think of e.g. the String.Empty property as a simple case of that. If your null object should have different behavior for some of it's methods, you make it a private inner class that derives from Category and overrides...

While it is common attitude to compose an entity of another entities or value objects, it is not necessary. Please remember that you should think about an abstraction. Primitive types are ok when there is no business logic involved in using them. For example: public class User { private UserId...

this was quickly done up so it's not perfect but you get the gist of it: public class User { public Guid UserId { get; set; } } public class Document { public string Name { get; private set; } private ICollection<User> sharedWith = new List<User>(); private DateTime? publishedOn; public...

It seems you're basically talking about sacrificing Command-Query Separation, which is a prerequisite to CQRS and an all-time good development practice anyway. If I were to move to a CQRS approach, I'd start by conforming to CQS if anything, separating queries from commands just at a method level, before bringing...

Good question. Command patter in its raw form is like GOF says. In CQRS the command is just a DTO (data transfer object) becasue CQRS is, in most cases, implemented with events or message bus that handles the command. In CQRS you send the command to the system and the...

Its a good question. Key thing to remember is that an event in an event sourced system represents something that has happened. Just because you change the logic in the future doesn't change the fact the event has already happened. How you deal with these events that have been deprecated...

The best way is to have only getters and a constructor. Then your DTO's are immutable. You can produce DTO's in two ways. One is to use JPA and queries like select new my_package.MyDto(u.username, u.email) from User u. The second which is more popular for bigger dtos including many...

CQRS does not say that you should pre-calculate everything in the write side. When the state of the system changes through a command, events are created and projections listen to these events and create a model that can be used for querying. What this model looks like and what it...

Unit of Work control would typically be placed in the Application Service in DDD, so I guess that means option #2. Note though that your whole question might be due to an overcomplicated design. Too many Factories is generally a code smell -- especially the DomainFactory one :) Is there...

Here are the few things that I would do if I were to refactor this code: Writing numbers in your code is a bad thing, either you have defined them as constants like ENERGY_PER_WALK_FOR_DOG = 20 or a better way is to define a field in the table of Dog...

There are couple of good examples of value objects on SO, check this question. Value objects equality is established not by checking if they have the same id, but comparing values itself. One more thing to consider is that EF is not supporting value objects properly (NHibernate does)....