Access Control in Domain Driven Design

So where should I put the access control logic? According to this: https://softwareengineering.stackexchange.com/a/71883/65755 the policy enforcement point should be right before the call of the UserService.editProfile(). I came to the same conclusion: it cannot be in the UI because by multiple UIs we would have code repetition. It should be before the creation of domain … Read more

Reducing Repositories to Aggregate Roots

You are allowed to have any method you want in your repository 🙂 In both of the cases you mention, it makes sense to return the user with phone list populated. Normally user object would not be fully populated with all the sub information (say all addresses, phone numbers) and we may have different methods … Read more

How to map View Model back to Domain Model in a POST action?

I use an IBuilder interface and implement it using the ValueInjecter public interface IBuilder<TEntity, TViewModel> { TEntity BuildEntity(TViewModel viewModel); TViewModel BuildViewModel(TEntity entity); TViewModel RebuildViewModel(TViewModel viewModel); } … (implementation) RebuildViewModel just calls BuildViewModel(BuilEntity(viewModel)) [HttpPost] public ActionResult Update(ViewModel model) { if(!ModelState.IsValid) { return View(builder.RebuildViewModel(model); } service.SaveOrUpdate(builder.BuildEntity(model)); return RedirectToAction(“Index”); } btw I don’t write ViewModel I write Input … Read more

Why should I isolate my domain entities from my presentation layer?

Quite simply, the reason is one of implementation and drift. Yes, your presentation layer needs to know about your business objects to be able to represent them properly. Yes, initially it looks like there is a lot of overlap between the implementation of the two types of objects. The problem is, as time goes on, … Read more

What is the difference between domain objects, POCOs and entities?

My (non-standard) Layman definitions POCO – Plain Old %Insert_Your_Language% Object. A type with no logic in it. It just stores data in memory. You’d usually see just auto properties in it, sometimes fields and constructors. Domain object an instance of a class that is related to your domain. I would probably exclude any satellite or … Read more

Value vs Entity objects (Domain Driven Design)

Reduced to the essential distinction, identity matters for entities, but does not matter for value objects. For example, someone’s Name is a value object. A Customer entity might be composed of a customer Name (value object), List<Order> OrderHistory (List of entities), and perhaps a default Address (typically a value object). The Customer Entity would have … Read more

DDD – the rule that Entities can’t access Repositories directly

There’s a bit of a confusion here. Repositories access aggregate roots. Aggregate roots are entities. The reason for this is separation of concerns and good layering. This doesn’t make sense on small projects, but if you’re on a large team you want to say, “You access a product through the Product Repository. Product is an … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)