FAQ Database Discussion Community


Big collections in DDD using Entity Framework

c#,entity-framework,domain-driven-design
I try to use DDD to describe domain model and code first approach on mapping to database tables with entity framework (using fluent api). For example I have 2 entities: Clubs and Users. Club has many Users. And I need to add new User to Club. class User { public...

Should i do authorization on my Domain Services?

c#,authorization,domain-driven-design
I have the following domain service: pulic void DeleteCustomer(int customerId, string userIdentity, string userPassword) { //1º Do login operation to verify if the credentials are valid. customerRepository.DeleteById(customerId); } Let's say that I am consuming this code of ASP.NET MVC or Windows Forms application that has a login window. The login...

DDD entities to multi-task a business process?

domain-driven-design,bpms
I have a rather large aggregate root entity called Alert. When an Alert is created, several complex things occur, so they are captured in a business process model and executed in the BPM Engine (e.g., the "Handle Alert" process). There are various sets of data about the alert that can...

Two event based bounded contexts, how to load initial data?

domain-driven-design
How would I load initial data (from the UI let's say) when integrating two Bounded Contexts via messaging? Example: Bounded Context #1 - Airport Bounded Context #2 - User Agent (UI) - Responsible for displaying/updating Airplaines in the airport. When UI is just starting, I want to query the "Airport"...

Who is responsible for entity's mutation when domain event is raised? DDD

c#,domain-driven-design,cqrs,servicebus,domain-events
I've been learning about CQRS/ES. Looking at small example projects I often see events mutating the entity state. For instance If we look at the Order aggregate root: public class Order : AggregateRoot { private void Apply(OrderLineAddedEvent @event) { var existingLine = this.OrderLines.FirstOrDefault( i => i.ProductId == @event.ProductId); if(existingLine !=...

DDD (Domain Driven Design) Can I use inheritance ?

inheritance,domain-driven-design,composition,aggregateroot
Consider the following example: We have Order, and any order can be of diffrent types. The order has transactions, and each type of order can assign n-transaction. For example: OrderA must have one transaction. OrderB must have two transaction. OrderC can have n-transaction. When we update the value of the...

How to deal with value objects in Entity Framework?

entity-framework,domain-driven-design
How do I persist value objects in Entity Framework without polluting my domain model? EF (well, relational DBs in general) require me to define a key - which my value objects don't have out of the box, for example public class Tag : ValueObject<Tag> { private readonly string name; public...

How to model a warehouse application with DDD/CQRS/ES?

domain-driven-design,cqrs,event-sourcing
We want to model a warehouse application. Let us assume we identified the following real world objects: Articles(the things stored in the warehouse) Palettes (where the Articles are on) Compartments (the places in the racks where the palettes are stored in) There are the following constraints: A palette is in...

How should I handle persistence for referenced entities?

c#,entity-framework,repository,domain-driven-design
I'am using Entity-Framework and DDD. If I have a reference between two entities, how should I handle persistence? Do updates cascade? Suppose an Employer has reference to their Manager directly. If I change the Employee.Manager.Name, and save the Employee, does the Manager’s Name get changed?...

Dependency between repositories

c#,entity-framework,repository,domain-driven-design
I'm using Entity Framework with DDD. I have the following entities: Person, Customer, Employee Person is abstract. Customer and Employee inherit person. Person has references to the Person Address (List). Should I have a repository for each type or only for each concrete type? (Just Customer and Employee) Could I...

Value Object vs Data Transfer Object

java,design-patterns,serialization,domain-driven-design,data-transfer-objects
I was a part of one of the project where we were producing java webservice and publishing into server. Some other java application was consuming the web service through extjs. In that producer application was following Domain Driven Design. We were using two types of pojos , Domain Objects and...

Using framework event dispatcher to raise domain event

php,events,laravel,domain-driven-design,dispatcher
When i need to raise domain events, should i use framework specific Event Dispatcher or create my own Event Dispatcher that implemented by framework event dispatcher ? Since the framework has a really nice event dispatcher and the term of DDD said the domain layer should not dependent on any...

DDD: entities mapped to tables with lots of databse columns

c#,domain-driven-design,entities
I am trying to follow the DDD approach to constructing entities where the properties have private setters and public getters and assignment is done through the constructor. The problem with this approach seems to be when you hit a table that has alot of columns, we have one that has...

DDD aware of existance of an entity outside the context?

domain-driven-design
In my journey to try to learn DDD, I came with a simple problem. I have an aggregate root Assistant. That assistant can manage therapists. so I have: var assistant = GetAssistant(Id); var therapist = new Therapist("[email protected]"); assistant.Manage(therapist); repository.Save(assistant); the business rules says that if the therapist [email protected] is already...

What does an entity's constructor look like for DDD in php?

php,constructor,entity,domain-driven-design,ddd-repositories
I'm confused on what a constructor looks like in PHP using a DDD aproach. This is what I have so far: Entity class People { // Fields private $id; private $first_name; // required private $middle_name; private $last_name; // required private $phone; // required (or mobile_phone required) private $mobile_phone; private $email;...

In Domain Driven Design, may a transaction modify more than one aggregate?

java,transactions,domain-driven-design,aggregateroot
In "Domain Driven Design: Tackling Complexity in the Heart of Software", Evans defines An Aggregate is a cluster of associated objects that we treat as a unit for the purpose of data changes. Obviously this implies that an aggregate must be updated in a single transaction. However, must a transaction...

DDD: Can an entity have attributes of primitive data types?

object,attributes,entity,domain-driven-design,value
The domain driven design differentiates two model types: entities and value objects. In the most examples the attributes of an entity are value objects or other entities, while the attributes of a value object are mostly simple strings, integers etc. (i. e. primitive data types). That leads me to the...

Location of Shared Kernel in Onion Architecture

architecture,domain-driven-design,onion-architecture
I'm creating an application using Onion Architecture for the first time. All the concepts of the Onion Architecture make perfect sense to me so far but what I'm wondering is, where do you place Domain Driven Design's "Shared Kernel" within the Onion Architecture? I've seen some people say it should...

What is the difference between Invariants and Validation Rules?

validation,domain-driven-design,invariants
I often see the term Invariants in DDD. Here Dino Esposito talks about it. If I look at the .NET library, I see a ValidationAttribute class. Are Invariants and validation rules the same? For example, can I say 50% discount is available only if the order total is more than...

DDD Aggregates Validation

domain-driven-design
I am building an application that will expose part of its features through RESTful services and my application packages is organized as below Application --> This package contains the RESTfull services Model --> Contains the domain model the aggregates, Value Objects,... Infrastructure --> Contains the set of classes required to...

Domain Driven Design - When to seperate one bounded context into two

domain-driven-design
While learning domain driven design, I learnt that we should keep two bounded contexts independent from each other. However I am having trouble decoupling two bounded contexts that really dependent on each other. To be more specific, I am designing a Point Of Sales system. It has a Inventory management...

Dealing with queued command handler response. CQRS

c#,domain-driven-design,messaging,cqrs,masstransit
Consider the situation: public class OrderController { IBus bus; public OrderController(IBus bus) { this.bus = bus; } public ActionResult Checkout(String orderId) { var command = new CheckoutOrderCommand(orderId); bus.Send(command); return Redirect("on-success-url"); } } The corresponding command handler (defined in a separate assembly) is awaiting for the incomming message to be processed....

In DDD how to pass Value Objects via DTO?

c#,domain-driven-design,dto,value-objects
In my domain each Domain Entity may have many Value Objects. I have created value objects to represent money, weight, count, length, volume, percentage, etc. Each of these value objects contains both a numeric value and a unit of measure. E.g. money contains the monetary value and the currency ($,...

Application Services Composition

c#,service,repository,domain-driven-design
I've a Customer entity that has an referente to City: public class Customer { public int CustomerId { get; set; } public int CityId { get; set;} } Then, the following application service: public class CustomerService { private readonly ICustomerRepository customerRepository; public CustomerService(ICustomerRepository customerRepository) { this.customerRepository = customerRepository; } public...

Bounded Contexts Rules Orchestration

design-patterns,domain-driven-design,business-rules
My banking core domain has divided into 2 distincts bounded contexts BC1 and BC2. These BCs deal with very specific business rules and processes (custom agreement for debt recovery, and administrative indebtedness with legal obligations). BC1 and BC2 are accessed through WebServices from a CRM. A client can't have both...

Asp.Net MVC 4 view model and domain model ids

c#,asp.net-mvc-4,design-patterns,domain-driven-design,viewmodel
Our system runs on multiple servers. All the tables in our system uses GUID as the Primary Key and Foreign Key fields. This is however our old system and it it going through a brand new rewrite. The motivation to use GUID in the old system was for migration of...

Consensus between DDD and Enterprise Architecture

architecture,domain-driven-design,enterprise,architectural-patterns
In literature (blogs, articles, books on Enterprise Architecture...), it seems there is a real (and exclusive) appliance of SOA in EA. If we consider DDD and SOA share common architecture principles but differ on many others, what is the place for DDD in the EA discipline ?

Entity VS Id as Parameter

c#,performance,domain-driven-design
I'm using DDD. I have the following interfaces: interface ICustomerRepository { void Disable(int customerId); } interface ICustomerService { void Disable(int customerId); } The application will work on a WebService. I wonder, should I use id's as parameter or the entire Customer entity? What are the pros and cons of each...

DDD: naming convention for Representation Layer and Domain Layer classes

java,rest,domain-driven-design,representation
I apologize in advance because this question is almost a bit silly. Nonetheless, I can't come up with a good solution myself, so I thought it still worthwhile to ask. What does one do when the Representation object and the Domain object should have the same name? The DDD Sample...

Mapping a Component inside a Component Collection

nhibernate,fluent-nhibernate,domain-driven-design
I'm trying to map a value object collection where these contain other value objects but am getting the below exception. nHibernate Exception: ----> NHibernate.PropertyNotFoundException : Could not find a getter for property '_timeAtAddress' in class 'CustomerAddress' Domain: public class CustomerAddress { private TimePeriod _timeAtAddress; protected CustomerAddress() { } public CustomerAddress(TimePeriod...

How to create a ddd aggregate and update other aggregate with its reference in the same transaction?

java,domain-driven-design
I would like to ask about a problem I have using DDD in the implementation of a game. I have a situation where, based on a message the system receives, a new aggregate for a player is created. The problem comes from the fact this new aggregate has to be...

How to create domain entity using data received from other bounded context?

domain-driven-design
I have scenario where i will get a information from other bounded context through messaging queue, I need to build the domain entity using the information received from message queue(construction of entity may vary depending on the information). Now, do i need to create the domain entity in infrastructure level...

Can Value Object have behaviour?

domain-driven-design,value-objects
I have a Value Objects - Money and ExchangeRatio. I want to convert one Money to another using ExchangeRatio. So is it good to build a convert behavior on Value Object ExchangeRatio like so: ExchangeRatio.Convert(Money) returns Money. Or should I delegate it to some Domain Service instead? In other words...

Domain model in DDD having same behaviors

c#,domain-driven-design
I am new to the DDD architecture pattern. I am designing the behaviors on my domain based on the Use Cases that were captured. I am not putting the logic in the behavior just creating the signatures. My question is what is best approach when 2 Domain model share or...

What properties on Department domain entity for CQRS

domain-driven-design,cqrs
I'm trying out in CQRS for the first time and need some advice. In my business, a department can be renamed. To do this, I dispatch a RenameDepartment command, caught by a command handler. This handler will then invoke the rename method on the Department entity, should this do anything...

DDD logic and Persistence Ignorance

c#,.net,orm,domain-driven-design,persistence
Consider the following scenario: public class Document { private ISet<User> sharedWith; public Document(string name) { this.sharedWith = new HashSet<User>(); this.Name = name; } public string Name { get; private set; } public IEnumerable<User> SharedWith { get { return this.sharedWith; } } public void ShareWith(User user) { if (this.SharedWith.Contains(user)) { throw...

Domain Driven Design : Can aggregate root have public setter?

design-patterns,repository,domain-driven-design
If I have a aggregate root says User It have property like public class User:BaseEntity { public User() { //Ef Use } public User(string firstName, string secondName, string userName,Password password ) { this.UserName = userName; this.Password = password; this.FirstName = firstName; this.SecondName = secondName; } public string UserName { get;...

CQRS and REST HATEOAS mismatch

rest,domain-driven-design,cqrs,hateoas
Suppose you have a model Foo. One business case is to simply create an instance of Foo, so there is a corresponding CreateFooCommand in my model, triggered by invoking a POST request to a given REST endpoint. There are of course other Commands too. But now, there is a ViewModel,...

Where to place this invariant?

domain-driven-design
I'm working on a side project to learn and apply DDD within the "Daily Deal' domain. In my purchasing context, i have an invariant where a user can only purchase 'x' amount of deals per deal. so it seems wasteful for my deal aggregate to load all purchases from all...

Are entity classes exclusive to one aggregate

domain-driven-design
After reading Evans and Vernon I still have one fundamental Question. I'm aware that of course one entity (instance) can only be in one aggregate. But can an entity class be used in multiple aggregates (classes)? For clarification, I ask on the class level. Other formulation: Can two different aggregate...

Database externalization in Onion/Hexagonal architecture

architecture,domain-driven-design,onion-architecture
I thinking about writing an app using an onion/hexagonal architecture pattern. I'm stuck on a database externalization. My app need to make some complex data queries to fulfill a use cases. I have two aggregates "A" and "B" and they are related. To fulfill UseCase1 I need to get all...

How do I test a component were the output goes to a database using Cucumber?

java,testing,tdd,cucumber,domain-driven-design
Recently there was a discussion in my team about how to properly test a component of our system where the output is stored in a database. We use DDD to create our system so the component ultimately talks to a repository that has different stores implemented to talk to a...

Do I need to test the domain services in Domain driven design?

domain-driven-design
I am developing a console application using domain driven design, i tried to keep the domain logic as much as possible into domain entities, but some how, some logic leaked into domain services, so now, do i need to test the domain services, if yes how to do it?

Should i validate if related entity exists before insert?

c#,entity-framework,domain-driven-design
class Customer { public int Id { get; set; } } class Sale { public int Id { get; set; } public int CustomerId { get; set; } } class SaleService { public void NewSale(Sale sale) { //Should i validate if Customer exists by sale.CustomerId before call save? saleRepository.InsertOrUpdate(sale); }...

Domain Logic and Referencing AR by ID

domain-driven-design,aggregateroot
I am trying to model a simple application using DDD. Consider the following simplified code where the idea is to hide a Comment if its parent Post is hidden: class Post { private $hidden; public function isHidden() { return $this->hidden; } } class Comment { private $post; private $hidden; public...

DDD Repository: Use DAO for separation?

domain-driven-design,repository-pattern,dao
There is a controversial discussion of Repositories, their use and layout on stackoverflow and throughout the web. I am confused about how to implement the data access abstraction (e.g. database) behind a Repository efficiently. I am not using an ORM tool/framework as I want to see the gritty details myself....

Where to implement data access for an aggregate root entity accessor method

domain-driven-design,aggregateroot
I have an aggregate root named Account and an entity named Contact that can be accessed through a method on the root: Account.GetContactById(string id). Access to the aggregate root is through a repository, so data access logic to get Accounts from storage resides there. Where should the data access logic...

Is Domain-Driven Design a right fit for a product in Enterprise Architecture Domain?

domain-driven-design,product-development
Our client has a requirement to re-design from scratch a product in an Enterprise Architecture Business Domain. The product has an ability to model business processes, information, technology, infrastructure, data etc. for the entire organization of the end user with the help of standard E.A. Framework methods & tools like...

Where do value objects come from in DDD?

domain-driven-design,value-objects
I am currently working on side project to get a feel of DDD, and I am wondering what would be the repository-ish component to get my value objects from. In my marketplace bounded context, a Catalog is managed by a Merchant and contains Offers organized in Categories and Universes here,...

How to make the data access technology (Entity Framework) ignorance from the presentation layer (ASP.NET MVC)?

c#,architecture,asp.net-mvc-5,domain-driven-design,entity-framework-6
Premise: I am exercising Domain-Driven Design and I separate my solution into 4 layers: Presentation Layer An ASP.NET Web API 2 project for a RESTful API web service An ASP.NET Web MVC5 project for a documentation and admin screens Application Layer A class library project responsible to take commands from...

Domain Driven Design - Atomic transaction across multiple bounded context

domain-driven-design
In DDD, I understand that Events can decouple the Bounded Contexts when they communicate with each others. Assume an atomic transaction contains two database operations on seperated bounded contexts A and B. When operation on A finishes it sends and event which is handled by B which finishes second operation....

Aggregate for one entity

entity,domain-driven-design,aggregate,ddd-repositories,aggregateroot
In Domain-driven design if I want to use a repository I need to have an aggregate for it - as I understand. So I have a User, that has id, login, email, and password. A user is a domain Entity with unique Id. When i want to add a User...

Implementing Bounded Context with Entity Framework in a 3-Layer Architecture

entity-framework,domain-driven-design,n-tier-architecture,bounded-contexts
I have watched Julie Lerman's videos about using EF in an enterprise application. Now I am developing a website using "Bounded Contexts" and other stuff she has taught in that series. The problem is I do not know how to use bounded contexts (BC) from within my "Business Layer". To...

Null entities in DDD

c#,null,domain-driven-design,nullable
Take an example of a Product entity or aggregate which has a reference to another entity called Category. Before a domain event like CategorizeProduct happens, the Category's state is empty. To represent that in C#, I have to use NULL. I can't use Nullable<T> in C# because that can be...

How to avoid anemic data model? Can repositories be injected into entities?

java,oop,design,domain-driven-design
I have an immutable User entity: public class User { final LocalDate lastPasswordChangeDate; // final id, name, email, etc. } I need to add a method that will return information if the user's password must be changed i.d. it has not been changed for more than the passwordValidIntervalInDays system setting....

Namespace for (DDD) entities cutting across domains

namespaces,domain-driven-design,modeling
I have a couple of business-related domains like Purchase, Marketing and Economy. Having the models arranged into a namespace* for each domain would be nice, but there are some entities cutting across domains, like an Item. How to organize those cross-cutting objects? * = As in C#/Java/Python namespaces....

Size of a bounded context

domain-driven-design,bounded-contexts
I've started learning the principles of DDD and I'm currently trying to get a grasp of the concept of a bounded context. In particular, how do you decide just how big (or small) it has to be? Yeah, I know, as small as possible and as big as necessary (according...

Layered architecture mvc

model-view-controller,domain-driven-design,layer,application-layer
I'm creating a web app using an MVC framework. I thought of adding a layer between the controller and the domain models, I think it's called application layer in DDD, to avoid putting logic that is specific to a certain use case in the domain models. The controller will only...

Autofac Generic Multiple Interface

c#,dependency-injection,domain-driven-design,inversion-of-control,autofac
I am trying to resolve one generic interface something like below but I am getting exception when trying to run the application . public interface IHandler<in T> where T : IDomainEvent { void Handle(T args); } public class ApplicationUserCreatedEventHandler : IHandler<ApplicationUserCreatedEvent> { public void Handle(ApplicationUserCreatedEvent args) { if (args ==...

Database field with multiple allowed value types

c#,postgresql,nhibernate,fluent-nhibernate,domain-driven-design
I am using Fluent NHibernate in my ASP.NET MVC Application to retrieve and save data to a Postgresql database. Say you have a table which holds Fields {Name, DataType, Value} //Model public class Table { public virtual string Name { get; set;} public virtual string DataType { get; set;} public...

What is the place for input validation general rules in Domain Driven Design?

domain-driven-design
I am developing a system following Domain Driven Design technics, my goal is to capture employees clock in and clock out. One requirement is that the system cannot permit two consecutive clocks for the same employee in a given time span. My question is where does this rule fits better,...

Domain Driven Design and batch processing

php,doctrine2,domain-driven-design,batch-processing
Has the following structure: Presentation Level: Web Interface, REST API and command prompt - all call only OrderService. Application Layer: class OrderService { private $em; private $repository; private $calculator; public function __construct( \Doctrine\ORM\EntityManagerInterface $em; ClientRepositoryInterface $repository, cumulativeDiscountCalculator $calculator } { $this->em = $em; $this->repository = $repository; $this->calculator = $calculator; }...

Use of ValueObjects

design-patterns,domain-driven-design
I am developing with Entity Framework (Database First and Code First). Most of the time, I am using entities in my domain models, mapped to dedicated tables. In DDD, there is the concept of ValueObjects, that should have no identity and should be immutable. Based on your experience with DDD,...

PHP - Where should Unit Of Work lie in an MVC application?

php,model-view-controller,domain-driven-design,unit-of-work
Background Info for Question In my index.php file I have this: $service_factory = new ServiceFactory(new MapperFactory($db), new DomainFactory); My understanding of how a UnitOfWork should work with my application is this (state is referring to dirty, clean, etc.): Mapper - marks an object's state Either $user->markNew(); or $uow->registerNew($user); Domain -...

What's the recommended way to load an object graph from Data Access Layer?

c#,architecture,domain-driven-design,data-access-layer,software-design
From a relatively old software architecture book: In other situations, the same conceptual Get-Orders query might generate different data—for example, a collection of Order objects plus order items information. What should you do? Should you expose two slightly different GetOrders methods out of your DAL? And what if, depending on...

Domain Driven Design for Rails App: Implementing a service in a basic example

ruby-on-rails,ruby,design-patterns,domain-driven-design,component-based
Two Models: An Owner and a Dog: owner.rb class Owner < ActiveRecord::Base has_one :dog end dog.rb class Dog < ActiveRecord::Base belongs_to :owner end And here is the schema: schema.rb ActiveRecord::Schema.define(version: 123) do create_table "dogs", force: true do |t| t.string "name" t.integer "energy" t.integer "owner_id" t.datetime "created_at" t.datetime "updated_at" end add_index...

Domain Events without Service Location

c#,domain-driven-design,ninject,inversion-of-control
Giving the default implementation of Domain Events: Interface that represents an domain event: public interface IDomainEvent { } Interface that represents a generic domain event handler: public interface IEventHandler<T> where T : IDomainEvent Central access point to raise new events: public static class DomainEvents { public static void Raise<T>(T event)...

Dynamic content display with Naked Objects or Dynamic Data

c#,jquery,domain-driven-design,dynamic-data,naked-objects
I need to develop a POC (.NET, C#, ASP.NET...). The application should create WebPages dynamically from domain objects. The application is about collecting new potential clients and it is a lot about UX. In such scenarios, we often need some kind of JQuery to show or hide fields according to...