If you create systems in which business processes depend on time [1], you cannot use DateTime.Now or the like in your code, since you will have to deal with tests, for example, future scenarios of the end of the month or the end of the year. Changing the operating system time is usually not an option when using SSL certificates and because it is difficult to do it right for a distributed system.
One option is to create a singleton service, available on all systems, that returns the current time. In production, he could return DateTime.Now , and in tests he could return playing time, like February 28, in the script for the end of the month.
But is there a better way to do this? Like a more database-based approach, since it leads to increased productivity? Or would you enable distributed cache? Is there any known design pattern for this?
[1] typical example: business processes implemented by the insurance system, the main banking system, ...
source share