A value is dependency data available from an object's known state that remains unchanged during the operation consuming it. Immutable constructor state, such as a maximum-entry limit, qualifies as a value. section 6.5
Distinguish values from collaborators by how the dependency behaves:
- Treat immutable, already-available data as a value. section 6.5
- Treat mutable dependencies or proxies for data not yet in memory as collaborators. section 6.5
- Prefer values in functional-core code because collaborators require external calls and prevent output-based testing. section 6.5
Pass time as a value
Obtain the current time through an explicit service at the start of a business operation, then pass the resulting DateTime value through the domain logic. Prefer this over an ambient context when possible because plain values are easier to use and stub. section 11.6 section 11.8
Listing 11.17. Current date and time as an explicit dependency
public interface IDateTimeServer
{
DateTime Now { get; }
}
public class DateTimeServer : IDateTimeServer
{
public DateTime Now => DateTime.Now;
}
public class InquiryController
{
private readonly IDateTimeServer _dateTimeServer;
public InquiryController(
IDateTimeServer dateTimeServer) #1
{
_dateTimeServer = dateTimeServer;
}
public void ApproveInquiry(int id)
{
Inquiry inquiry = GetById(id);
inquiry.Approve(_dateTimeServer.Now); #2
SaveInquiry(inquiry);
}
}
Shows a service supplying time to a controller, which passes the resulting value into domain behavior. section 11.6






