Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
Why do I need to create a DateTime service which returns DateTime.Now instead of using DateTime.Now directly?

I have been watching Jason Taylor presentation about Clean Architecture with ASP.NET Core (timing 35:52)

https://www.youtube.com/watch?v=dK4Yb6-LxAk&t=2134s&ab_channel=GOTOConferences

And he created a DateTimeService which returns DateTime.Now and registered via AddTransient method, he suggests using it instead of using DateTime.Now directly because in this case he doesn't have a dependency on the machine clock.

It's not clear to me why he doesn't have a dependency in this case, could you please explain how it works?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you were ever going to implement a different way for getting the current time all you would need to do is create a new implementation for your IDateTimeService instead of changing every single instance of DateTime.Now in your project.

An example would be to create a service that obtains the time with an external request or to easily create a mock for unit tests so you can properly assert results that are dependent on the date and time.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!