Srutu-tutu
Srutu-tutu

Reputation: 35

DDD: Passing parameters to domain entity methods with app config/env variable values

Question about right approach to application design in DDD:

Client asked to set request status to 'Expired' after 10 days. Do I hardcode the value in the Request entity in the IsRequestExpired() method (Domain layer) like so:

public bool IsRequestExpired(DateTime now) 
{
    int daysToSetExpiredStatus = 10;
    return Created <= now.AddDays(-daysToSetExpiredStatus);
}

This seems to have the following drawbacks:

A solution would to both would be passing a value from application settings/env variables, like so:

public bool IsRequestExpired(DateTime now, in daysToSetToExpiredStatus) 
{
    return Created <= now.AddDays(-daysToSetExpiredStatus);
}

but is this still considered in line with DDD, as the invariant (expire after 10 days) is not really included in the Request entity (or the Domain layer whatsoever) any more but is fetched from config?

Upvotes: 1

Views: 533

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57214

is this still considered in line with DDD

Absolutely! In particular, it's not usually the responsibility of the "domain model" to decide where information comes from (reading from databases, or files, or the internet, or whatever is normally code you want in the application layer, not in the domain layer).

Upvotes: 2

Related Questions