Currently diving into DDD and i've read most of the big blue book of Eric Evans. Quite interesting so far :)
I've been modeling some aggregates where they hold a collection of entities which expire. I've come up with a generic approach of expressing that:
public class Expirable<T>
{
public T Value { get; protected set; }
public DateTime ValidTill { get; protected set; }
public Expirable(T value, DateTime validTill)
{
Value = value;
ValidTill = validTill;
}
}
I am curious what the best way is to invalidate an Expirable (nullify or omit it when working in a set). So far I've been thinking to do that in the Repository constructor since that's the place where you access the aggregates from and acts as a 'collection'.
I am curious if someone has come up with a solution to tackle this and I would be glad to hear it :) Other approaches are also very welcome.
UPDATE 10-1-2013:
This is not DDD with the CQRS/ES approach from Greg Young. But the approach Evans had, since I just started with the book and the first app. Like Greg Young said, if you have to make good tables, you have to make a few first ;)
Twould typically be in the "expirable invariant" scenario ? Where would you place the code that enforces the invariant ? - guillaume31UserSessionfor aT.UserSessionisn't an invariant in the DDD sense of the term - a business rule enforced by the Aggregate Root. Since you mentioned invariants, I was just curious to know how you implemented them withExpirable<T>. - guillaume31Useris theT. SoUseris the aggregate which maintains the enforcements of adding/removing/updating invariants (IEnumerable<Expirable<UserSession>>). Correct? - mark_dj