Picon

DDD and cross domain AR references for UI



This question relates to discovering other representations of an AR across multiple BC's.

This is an entirely made up example but I hope makes my question clear.

Let's imagine some sort of site where people book tickets to shows but also share and socialise.

In one BC I have everything to do with tickets and booking shows. The user is represented as a relatively light object: TicketHolder

In a 'social' BC I have a richer representation of a User with profile information and relationships to other users.

One day we decide that a Company can be a TicketHolder. The DDD approach really helps us because the Ticket BC doesn't need to change in the case. Big win!

However in our UI there is a page that shows the information on a purchas ed Ticket that includes the TicketHolder. We have decided we would like to be able to click on the TicketHolder link and go to the User or Company's full profile.

When the TicketHolder is created in the Ticket BC we could add a 'type' which is a string ('company' | 'user') and return that back into the UI and juggle the type with some RESTful endpoints - but that seems brittle :(

Does anyone have any pointers? I'd be most grateful. Either technically (i.e. some sort of URN/HATEOS/ discovery system) or perhaps from a modelling perspective (i.e. you're modelling it wrong!).

Best regards,
Doug

__._,_.___
Posted by: douglas <at> reith.com.au



__,_._,___
Picon

DDD Could Have Saved The Day



Recently, I was reminded of one of the reasons I love DDD.

I recently encountered a production problem that, it turns out, could have been avoided if one particular DDD pattern had been followed:Never create an entity in an inconsistent state.  By adhering to this, it becomes syntactically impossible to encounter an invalid entity.

In this case, there was an entity that could be created in an invalid state: Settings.  A Settings has a TaskDefinition child entity.  The schema correctly enforced a NOT NULL FK constraint for the child entity; however, the Settings constructor did not accept nor instantiate its own TaskDefinition.

The code that broke looked something like this:

1. var settings = new Settings(...)
2. // do some other stuff
3. settings.TaskDefinition = new TaskDefinition(...)
4. Commit

This is a .NET system using NHibernate.  This code happened to work in local and QA testing, but broke in production.  The production system had additional data and configurations that drove the complex logic behind step 2 to do quite a bit more than it had in the local or QA tests.  This extra work filled up NHibernate's buffer to the point that it decided to automatically flush it, including the invalid Settings object, before step 3.  The outcome: a SqlException ruining my morning.

The code was fixable with a little refactoring; however, I wish it hadn't gotten that far.  If our no invalid entities DDD guideline had been adhered to, it wouldn't have gotten that far.




__._,_.___
Posted by: trin <at> trinition.org



__,_._,___
Picon

CQRS, Event-Sourcing and Web-Applications



Hello,

As I am reading some CQRS resources, there is a recurrent point I do not catch. For instance, let's say a client emits a command. This command is integrated by the domain, so it can refresh its domain model (DM). On the other hand, the command is persisted in an Event-Store. That is the most common scenario.

1) When we say the DM is refreshed, I suppose data is persisted in the underlying database (if any). Am I right ? Otherwise, we would deal with a memory-transient model, which I suppose, would not be a good thing ? (state is not supposed to remain in memory on server side outside a client request).

2) If data is persisted, I suppose the read-model that relies on it is automatically updated, as each client that requests it generates a new state in the application (in case of a Web-Application or a RESTful architecture) ?

3) If the command is persisted, does that mean we deal with Event-Sourcing (by construct when we use CQRS) ? Does Event-Sourcing invalidate the database update process ? (as if state is reconstructed from the Event-Store, maintaining the database seems useless) ?

Does CQRS only apply to multi-databases systems (when data is propagated on separate databases), and, if it deals with memory-transient models, does that fit well with Web-Applications or RESTful services ?

Thanks,

Rénald




__._,_.___
Posted by: =?UTF-8?Q?R=C3=A9nald_VENANT=2DVALERY?= <r.venant.valery <at> gmail.com>



__,_._,___
Picon

Value object with set of aggregate roots?



We are working on an administrative system with quite a large amount of aggregate roots. We have a hexagonal architecture, where a single hexagon handles a specific type of calculation using a separate product (and therefore a separate bounded context). Certain calculations performed within this hexagon require a list of roots. The reason for this is twofold:

  • This hexagon requires a “picture” of the customer for which the calculation is performed. This picture represents the situation of that customer at a certain moment in time. This includes both personal information about the customer, but also additional information, which in contained within separate roots in the domain model.
  • Another functional responsibility of this hexagon is to create a fictional situation for the provided roots. This can for instance be a future situation, where certain events are being applied to multiple roots

·    

The question is how to model this picture class containing a set of aggregate roots. Should this be an entity or a value object? A value objects seems the best choice, but this would imply that the picture would be immutable. Given that the picture contains various Aggregates which are themselves mutable, this would not hold. Due to the potential changes in one or more aggregate, one could argue it cannot be a value object, as it is mutable. Modelling this object as an Entity would be the other option. It that case, the question is what the identity of this entity should be. Also, this would imply that we have an aggregate which is built-up out of other aggregates, which also seems like a strange design.




__._,_.___
Posted by: dennis.vredeveld <at> yahoo.com



__,_._,___
Picon

testing the domain model



I'm wondering if anyone has any advice for creating and managing test data for testing the domain model. entity aggregates can be quite complicated and repetitive to create, especially when you find yourself needing variants of the same things across several tests (how many things require a reference to a user?). I'm especially interested if you want to create the aggregates for cases where persistence is not required/desired.
--
Caleb Cushing


__._,_.___
Posted by: Caleb Cushing <xenoterracide <at> gmail.com>



__,_._,___
Picon

Working with Polymorphic Child Entities



I have been thinking of the best approach to deal with Aggregate Entities having polymorphic children and wonder if anyone could tell me if implementation below is a correct implementation or if I may be overlooking some potential pitfalls.

The following code demonstrates a system for sending some sort of communication on varying schedules.

THE DOMAIN

class Delivery { Dictionary<Type, Func<ScheduleDto, ScheduleEntity>> ScheduleFactories = new Dictionary<Type, Func<ScheduleDto, ScheduleEntity>> { { typeof(DailyScheduleDto), GetDailySchedule}, { typeof(HourlyScheduleDto), GetHourlySchedule} }; public Guid Id { get; private set; } public string Message { get; private set; } public StatusEnum Status { get private set; } public Schedule { get; private set; } public Delivery(DeliveryDto dto){ Id = dto.Id; Message = dto.Message; Status = StatusEnum.New; Schedule = ScheduleFactories[dto.Schedule.GetType()](dto.Schedule); } public void Update(DeliveryDto dto){ Message = dto.Message; Schedule.Update(dto.Schedule); } public DateTime GetNextExecution(DateTime after){ return Schedule.GetNextExecution(after); } public enum StatusEnum { New, InProgress, Complete } Schedule GetDailyScheduleEntity(ScheduleDto dto){ return new DailyScheduleEntity((DailyScheduleDto)dto); } Schedule GetHourlyScheduleEntity(ScheduleDto dto){ return new HourlyScheduleEntity((HourlyScheduleDto)dto); } } abstract class Schedule { public DateTime StartsOn { get; private set; } public abstract DateTime GetNextExecution(DateTime after); public virtual void Update(ScheduleDto dto){ StartsOn = dto.StartsOn; } public Schedule(ScheduleDto dto) { StartsOn = dto.StartsOn; } } class DailySchedule : Schedule { public DaysEnum Days { get; private set; } public override DateTime GetNextExecution(DateTime after){ return // logic for calculating the next day based on Days; } public DailySchedule(DailyScheduleDto dto) : base(dto) { Days = dto.Days.ToEnum<DaysEnum>(); base.Update(dto); } public override void Update(ScheduleDto dto){ if(!(dto is DialyScheduleDto)) throw new InvalidOperationException(); Days = ((DailyScheduleDto)dto).Days.ToEnum<DaysEnum>(); } [Flags] public enum DaysEnum{ Monday, Tuesday, Wednesday, Thursday, Friday } } class HourlySchedule : Schedule { public int Interval { get; private set } public override DateTime GetNextExecution(DateTime after){ return // logic for calculating the next hour based on interval; } public HourlySchedule(HourlyScheduleDto dto) : base(dto) { Interval = dto.Interval; } public override void Update(ScheduleDto dto){ if(!(dto is HourlyScheduleDto)) throw new InvalidOperationException(); Days = ((HoulryScheduleDto)dto).Interval; base.Update(dto); } } class DeliveryService : IDeliveryService { public void Add(DeliveryDto dto){ var delivery = new Delivery(dto); var scheduledTask = new ScheduledTask( delivery.Id, delivery.GetNextExecution(after: DateTime.Now) ); unitOfWork.Add<ScheduledTask>(scheduledTask); unitOfWork.Add<Delivery>(delivery); unitOfWork.SaveChanges(); } public void Update(DeliveryDto dto){ var delivery = unitOfWork.Get<Delivery>(dto.Id); delivery.Update(dto); unitOfWork.SaveChanges(); } public void SendAll(){ var scheduledTasks = unitOfWork.GetAll<ScheduledTask>(st => st.ExecutionDateTime < DateTime.Now && st.Status == ScheduledTaskStatus.New); scheduledTasks.ForEach(//Send to subsystem for execution); } }

CONTRACTS

DeliveryDto{ Guid Id {get; set;} string Description {get; set;} ScheduleDto Schedule {get; set;} } ScheduleDto{ DateTime StartsOn {get; set;} } HourlyScheduleDto : ScheduleDto{ int Interval {get; set;} } DailyScheduleDto : ScheduleDto{ String Days {get; set;} }

I would typically have specific dtos for creating new instances and performing updates, but reuse the same types here for simplicity.

Although there is an argument that passing Dtos directly to Entities would tightly couple clients to the domain, my intention is to provide a thin facade-type layer that would be responsible for 'upgrading' dtos to maintain compatibility with existing clients should the current dto's need to change to accommodate changing business needs




__._,_.___
Posted by: ricardods100671 <at> yahoo.com



__,_._,___
Picon

Domain Event Objects vs Standard Events



What's everyone opinion on using (assuming .NET) standard custom events as opposed to the traditional DDD way (static domain publisher class)?


sure you are more tightly coupled, but I would think in most instances the client of the domain model is the application layer and this type of coupling is not very harmful. The application layer has enough knowledge for the given use case on how to dispatch the events, in-process, on the bus, in-line, etc.


I don't see many people talking about this approach and I was wondering why? here is some pseudo-code i've been toying around with.


            Deferred deferred = new Deferred();


&nb sp;           Consignee consignee = new Consignee();


            consignee.Created +=

                (s, e) => deferred.Enlist(() => Bus.Publish(e));


            repository.Add(consignee);


            deferred.Continue();





__._,_.___
Posted by: mpaul3133 <at> yahoo.com



__,_._,___
Picon

Bounded Contexts Rules Orchestration



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 a custom agreement and an indebtedness plan, and each situation exclude the other one. So we need to orchestrate both types of processes (more precisely we need to enforce in each BC that actions are permitted, on both sides).

How would you orchestrate them ? Would you inject a bit of knowledge of BC1 in BC2 domain model, and vice-versa, or do you think we should rely on a third BC (BC3) that could orchestrate the system, and would be aware of both business knowledges, and through a third WebService for instance ? We just need to know if the client has an agreement with the company, or if it is officially and legaly indebted.

Do you think having BC1 to know "a little" of BC2 business is violating DDD principles ? In case of an orchestrator or a p roxy, would you use WebServices, or SharedKernel ? What are the pros and cons of SharedKernel versus WebServices ?

Many thanks,



__._,_.___
Posted by: =?UTF-8?Q?R=C3=A9nald_VENANT=2DVALERY?= <r.venant.valery <at> gmail.com>



__,_._,___
Picon

Working with Polymorphic child Entities



I have been thinking of the best approach to deal with Aggregate Entities having polymorphic children and wonder if anyone has comments on whether the following implementation is correct or whether I may be overlooking some potential pitfalls.

The following code demonstrates a system for sending some sort of communication on varying schedules. User will typically create a Delivery with a m essage and assign one of two types of Schedule, Hourly' or 'Weekly'. A Windows Service will periodically poll the Data Store to identify Deliveries ready top be sent 

THE DOMAIN

class Delivery {
    Dictionary<Type, Func<ScheduleDto, ScheduleEntity>> ScheduleFactories = 
       new Dictionary<Type, Func<ScheduleDto, ScheduleEntity>> {
            { typeof(DailyScheduleDto), GetDailySchedule},
            { typeof(HourlyScheduleDto), GetHourlySchedule}
       };
    public Guid Id { get; private set; }
    public string Message { get; private set; }
    public StatusEnum Status { get private set; }
    public Schedule { get; private set; }
    public Delivery(DeliveryDto dto){
& nbsp;       Id = dto.Id;
        Message = dto.Message
        Status = StatusEnum.New;
        Schedule = ScheduleFactories[dto. Schedule.GetType()](dto. Schedule);
    }
    public void Update(DeliveryDto dto){
        Message = dto.Message;
        Schedule.Update(dto.Schedule);
    }
    public DateTime GetNextDeliverySchedule( DateTime after){
        return Schedule. GetNextDeliverySchedule(after) ;
    }
    public enum StatusEnum { New, InProgress, Complete }
    Schedule GetDailyScheduleEntity( ScheduleDto dto){
      &nb sp; return new DailyScheduleEntity(( DailyScheduleDto)dto);
    }
    Schedule GetHourlyScheduleEntity( ScheduleDto dto){
        return new HourlyScheduleEntity(( HourlyScheduleDto)dto);
    }
}
abstract class Schedule {
    public DateTime StartsOn { get; private set; }
    public abstract DateTime GetNextDeliverySchedule( DateTime after);
    public virtual void Update(ScheduleDto dto){
         StartsOn = dto.StartsOn;
    }
    public Schedule(ScheduleDto dto) {
        StartsOn = dto.StartsOn;
    }
}
class DailySchedule : Schedule {
    public DaysEnum Days { get; priv ate set; }
    public override DateTime GetNextDeliverySchedule( DateTime after){
       return // logic for calculating the next day based on Days;
    }
    public DailySchedule(DailyScheduleDto dto)
        : base(dto)
    { 
        Days = dto.Days.ToEnum<DaysEnum>();
        base.Update(dto);
    }
    public override void Update(ScheduleDto dto){
        Days = ((DailyScheduleDto)dto).Days. ToEnum<DaysEnum>();
    }
    [Flags]
    public enum DaysEnum{
        Monday, Tuesday, Wednesday, Thursday, Friday
    }
}
class HourlySchedule : Schedule {
    public int Interval { get; private set }
    public override DateTime GetNextDeliverySchedule( DateTime after){
       return // logic for calculating the next hour based on interval;  
    }
    public HourlySchedule( HourlyScheduleDto dto)
        : base(dto)
    {
         Interval = dto.Interval;
    }
    public override void Update(ScheduleDto dto){
        Days = ((HoulryScheduleDto)dto). Interval;
        base.Update(dto);
    }
}
class DeliveryService : IDeliveryService {
    &nbs p;public void Add(DeliveryDto dto){
         var delivery = new Delivery(dto);
         unitOfWork.Add<Delivery>( delivery);
         unitOfWork.SaveChanges();
     }
     public void Update(DeliveryDto dto){
          var delivery = unitOfWork.Get<Delivery>(dto. Id);
          delivery.Update(dto);
          unitOfWork.SaveChanges();
     }
}
 
CONTRACTS

DeliveryDto{
    Guid Id {get; set;}
    string Description {get; set;}
    ScheduleDto Schedule {get; set;}
}
ScheduleDto{
   DateTime StartsOn {get; set;}
}
HourlyScheduleDto : ScheduleDto{
   int Interval {get; set;}
}
DailyScheduleDto : ScheduleDto{
   String Days {get; set;}
}
 
I would typically have specific dtos for creating new instances and performing updates, but reuse the same types here for simplicity.

Although there is an argument that passing Dtos directly to Entities would tightly couple clients to the domain, my intention is to provide a thin facade-type layer that would be responsible for 'upgrading' dtos to maintain compatibility with existing clients should the current dto's need to change to accommodate changing business needs




__._,_.___
Posted by: ricardods100671 <at> yahoo.com



__,_._,___
Picon

Working with polymorphic Child Entities



I have been thinking of the best approach on how to deal with Aggregate entities that have polymorphic child entities and wonder if anyone has comments on whether this implementation is correct or whether I may be overlooking some potential pitfalls and what may be a better approach.

The following code demonstrates a system for sending some sort of communication on varying schedules. Users can create 'Deliveries' that contain messages to be sent on one of two types of schedule either 'Hourly' or 'Daily'. A separate Windos Service will constants poll the Data Store to identify Deliveries that need to be sent. 


THE DOMAIN

class Delivery {
    Dictionary<Type, Func<ScheduleDto, ScheduleEntity>> ScheduleFactories = 
       new Dictionary<Type, Func<ScheduleDto, ScheduleEntity>> {
            { typeof(DailyScheduleDto), GetDailySchedule},
            { typeof(HourlyScheduleDto), GetHourlySchedule}
       };
    public Guid Id { get; private set; }
    public string Message get; private set; }
    public StatusEnum Status { get private set; }
    public Schedule { get; private set; }
    public Delivery(DeliveryDto dto){
        Id = dto.Id;
        Message = dto.Message;
        Status = StatusEnum.New;
        Schedule = ScheduleFactories[dto. Schedule.GetType()](dto. Schedule);
    }
    public void Update(DeliveryDto dto){
        Message = dto.Message;
        Schedule.Update(dto.Schedule);
    }
    public DateTime GetNextDeliverySchedule( DateTime after){
        return Schedule. GetNext DeliverySchedule(after) ;
    }
    public enum StatusEnum { New, InProgress, Complete }
    Schedule GetDailyScheduleEntity( ScheduleDto dto){
        return new DailyScheduleEntity(( DailyScheduleDto)dto);
    }
    Schedule GetHourlyScheduleEntity( ScheduleDto dto){
        return new HourlyScheduleEntity(( HourlyScheduleDto)dto);
    }
}
abstract class Schedule {
    public DateTime StartsOn { get; private set; }
    public abstract DateTime GetNextDeliverySchedule( DateTime after);
    public virtual void Update(ScheduleDto dto){
         StartsOn = dto.StartsOn;
    }
&nbs p;   public Schedule(ScheduleDto dto) {
        StartsOn = dto.StartsOn;
    }
}
class DailySchedule : Schedule {
    public DaysEnum Days { get; private set; }
    public override DateTime GetNextDeliverySchedule( DateTime after){
       return // logic for calculating the next day based on Days;
    }
    public DailySchedule(DailyScheduleDto dto)
        : base(dto)
    { 
        Days = dto.Days.ToEnum<DaysEnum>();
        base.Update(dto);
    }
    public override void Update(ScheduleDto dto){
        Days = ((DailySchedul eDto)dto).Days. ToEnum<DaysEnum>();
    }
    [Flags]
    public enum DaysEnum{
        Monday, Tuesday, Wednesday, Thursday, Friday
    }
}
class HourlySchedule : Schedule {
    public int Interval { get; private set }
    public override DateTime GetNextDeliverySchedule( DateTime after){
       return // logic for calculating the next hour based on interval;  
    }
    public HourlySchedule( HourlyScheduleDto dto)
        : base(dto)
    {
         Interval = dto.Interval;
    }
    public override void Update(ScheduleDto dto){
& nbsp;       Days = ((HoulryScheduleDto)dto). Interval;
        base.Update(dto);
    }
}
class DeliveryService : IDeliveryService {
     public void Add(DeliveryDto dto){
         var delivery = new Delivery(dto);
         unitOfWork.Add<Delivery>( delivery);
         unitOfWork.SaveChanges();
     }
     public void Update(DeliveryDto dto){
          var delivery = unitOfWork.Get<Delivery>(dto. Id);
          delivery.Update(dto);
          unitOfWork.SaveChanges();
     }
}kquote>
 
CONTRACTS

DeliveryDto{
    Guid Id {get; set;}
    string Description {get; set;}
    ScheduleDto Schedule {get; set;}
}
ScheduleDto{
   DateTime StartsOn {get; set;}
}
HourlyScheduleDto : Schedul eDto{
   int Interval {get; set;}
}
DailyScheduleDto : ScheduleDto{
   String Days {get; set;}
}
 
I would typically have specific dtos for creating new instances and performing updates, but reuse the same types here for simplicity.

Although there is an argument that passing Dtos directly to Entities would tightly couple clients to the domain, my intention is to provide a thin facade-type layer that would be responsible for 'upgrading' dtos to maintain compatibility with existing clients should the current dto's need to change to accommodate changing business needs




__._,_.___
Posted by: ricardods100671 <at> yahoo.com



__,_._,___
Picon

How to model questionaire



Hello I am working on a Insurance Product. The challenge I am facing is on how to model the requirement related to Proposal. While creating the Proposal we ask lot of questions like 

  • Are any proposals for Life Assurance on your life pending with Professional Life Assurance Limited or any other insurer ?
  • Your heart circulation or blood vessels (e.g. rheumatic fever, heart murmur, chest pains, palpitations, blood pressure, stroke varicose veins etc.)?

I was thinking of a Proposal Aggregate and one of the associated value object would be an Enum to represent the fixed set of questions that are asked? Is there any other better way to model this.



__._,_.___
Posted by: raja_navy <at> yahoo.com



__,_._,___

Gmane