The Problem with Time That .NET 8 Finally Fixed

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024

Комментарии • 193

  • @nickchapsas
    @nickchapsas  Год назад +49

    Ignore the fact that in this example this code is running on the server. It's irrelevant to the point of this video. It could be a CLI tool or a Blazor Server app that runs locally as a Dektop app with Electron. Focus on the Time point.

    • @greysontyrud
      @greysontyrud Год назад +5

      did you post the link you mention at 7:09?

  • @Shadow_Play3r
    @Shadow_Play3r Год назад +168

    DateTimeOffset vs DateTime has always confused me. Some teams have contracts with offset others with stock.

    • @pilotboba
      @pilotboba Год назад

      DateTimeOffset is an unambiguous point in time where DateTime combines with the Kind property. So if you are trying to do the right thing and always use UtcNow() but you store it in a Datetime and don't set the Kind to UTC, some date/time conversions (like serialization) might not give you the results you expect.
      I think DateTimeOffset is more precise than Datetime as well.

    • @billy65bob
      @billy65bob Год назад

      You can feed dates with a time zone offset into a DateTime just fine, It'll localise it to the same instant in the local timezone with the proper DateTimeKind set.
      Whether the respects the Kind is a different matter alltogether (usually the answer is no)
      When it comes to data structures, when you care for the TimeZone (e.g. for localisation), you will generally use DateTimeOffset over DateTime. Unfortunately it's not always the case.

    • @AbrahamWilson
      @AbrahamWilson Год назад +18

      This. Please make a video on this.

    • @y.katlego
      @y.katlego Год назад

      Same

  • @clayMeisman
    @clayMeisman Год назад +103

    Can you please make a video about the datetimeoffset and why it's better over datetime?

    • @proosee
      @proosee Год назад

      @Dionte Smith in simple scenarios like you've just described it doesn't matter much.

    • @dputra
      @dputra Год назад

      Working in a company that employs employees in several timezones, having the timezone instead of using UTC built in could provide extra context. Is it created in the morning of creator's time? Is it edited in the afternoon of the editor's time?
      Without that, you have to lookup each users's timezone. Not very ideal if your employees crossing timezones frequently.
      And yes, it's not for everyone. If you are happy with UTC datetime, then use it.

  • @morganishere123
    @morganishere123 Год назад +17

    I'd created a IDateTimeProvider very similarly to the ISystemClock as you've referenced. I really like how they've put some of the Stopwatch functionality in this new TimeProvider class; it should make asserting time differences easier in unit tests (E.g. when you log how long a service took to run)

  • @ernest1520
    @ernest1520 Год назад +28

    It's good that they provide some framework-level time dependency like this. However, due to the issues that you just showed with setting up a mock, I'd rather stick to my custom IDateTimeProvider. What the team behind it should do is to provide an interface for the TimeProvider.

  • @madsxcva
    @madsxcva Год назад +21

    I treated DateTime variables as external dependencies (since they are when they are based on system time) and as consequence I would want to receive DateTime as a parameter. in the video example the endpoint would have a date parameter that then would be passed to the method

    • @maxbradley9534
      @maxbradley9534 Год назад

      Sure but then you are just passing the problem up the chain. Now that method that passes in the DateTime is not testable.

    • @madsxcva
      @madsxcva Год назад

      @@maxbradley9534 I am passing the responsibility to provide the date to the end user. That doesnt make the method non testable, on the contrary it makes the method that exists testable, because any unit test that uses DateTime.Now or other methods that rely on external resources should be considered failed tests . I can change the machine time and make it output whatever i want, thus the test is not consistent and is a bad test.

    • @benjamininkorea7016
      @benjamininkorea7016 Год назад +2

      @@madsxcva Eh? So when you're unit testing, you prefer to sit there for 24 hours? Because "consistent" time runs at a rate of 1 second per second.

  • @silentdebugger
    @silentdebugger Год назад +9

    I went even further beyond and created a TimeProvider interface which provides an overridable definition of Delay() (to replace Task.Delay()) so I can do deterministic unit testing of time-dependent code - for example I can make a unit test for "does a token expire from the token cache after 24 hours" just by fast-forwarding simulated time

    • @desertfish74
      @desertfish74 Год назад

      This is a great application for this

    • @ashbjorn
      @ashbjorn Год назад +1

      For my curiosity, how would it be any different than providing an instance of your interface where 24 hours would already have passed?

    • @oleggavrilov7083
      @oleggavrilov7083 Год назад

      Can you throw a quick example of your test and that TimeProvider? Github gist would be great

  • @TheBuzzSaw
    @TheBuzzSaw Год назад +38

    Since .NET 8 is far from finalized, the team should be made aware that this design is highly suspect.

  • @conway9214
    @conway9214 Год назад +12

    Looking forward for the DateTime vs DateTimeOffset video 🎉

  • @DeserdiVerimas
    @DeserdiVerimas Год назад +86

    This should totally have been an interface, that mocking setup is complicated.

    • @modernkennnern
      @modernkennnern Год назад

      On the GitHub PR there's a link to a 1.5hr RUclips video that - somewhere in it - contains an argument as to why it's not.
      If you can find it, please link it to me :p.. I saw the PR yesterday during break and I forgot about it

    • @garcipat
      @garcipat Год назад +4

      Agree 100%, this is ugly.

    • @jonathansaindon788
      @jonathansaindon788 Год назад +2

      Absolutely! I dont think the setup would be that much different tough…

    • @carl-henrikkristoffersen2313
      @carl-henrikkristoffersen2313 Год назад +1

      It's not that bad imo, pretty much anything you'd mock ends up being messy. Unless it's super simple unit tests.

    • @Ju57u5
      @Ju57u5 Год назад +1

      They will very likely provide a fake class so you won't need to mock it anyway and just use their implementation.

  • @ricmrodrigues
    @ricmrodrigues Год назад +1

    I've implemented this before as ambient context with a good default, such as the one you're using there, given it's a cross cutting, basic concern. Still solves it but no need to inject it everywhere.

  • @Saiyugi16
    @Saiyugi16 Год назад +7

    Re: DateTimeOffset vs DateTime I would appreciate to hear your perspective on the reason for which is better

  • @T___Brown
    @T___Brown Год назад +21

    Its better to have an excuse why i cant do a unit test

  • @frankhaugen
    @frankhaugen Год назад +14

    I would have preferred a minimalistic interface, but I followed the discussion as it was streamed on youtube, and I get why it is the way it is

    • @SamMackrill
      @SamMackrill Год назад +1

      Do expand a bit please

    • @ProfessorCodemunkie
      @ProfessorCodemunkie Год назад +9

      Do you have a link to this discussion please?

    • @frankhaugen
      @frankhaugen Год назад

      @@ProfessorCodemunkie ruclips.net/video/KVDnUSH90qI/видео.html

    • @Ju57u5
      @Ju57u5 Год назад

      @@ProfessorCodemunkie ruclips.net/video/KVDnUSH90qI/видео.htmlh34m27s

    • @ashbjorn
      @ashbjorn Год назад

      I believe AftercastGames is referring to this link? ruclips.net/video/WW65sGkDINQ/видео.html
      Edit: Seems this is a link to when the discussion was a bit older, but still relevant imo.

  • @billy65bob
    @billy65bob Год назад +4

    There's so much they can do with the built in DateTime object too with respect to its Kind, they could genuinely make it intuitive, but I don't expect them to because of legacy concerns.
    DateTime uses its Kind wrong in almost every single context; it cares about it when you don't, it disregards it when you care about it, and it makes ridiculous assumptions when you don't have one.

  • @zagoskintoto
    @zagoskintoto Год назад

    Love the vid. I'm really bad with dates, timestamps, etc. Glad to have content on this and hoping for more!

  • @sunilanthony17
    @sunilanthony17 Год назад

    It's like you're reading my mind. I'm currently working with datetime logic and had to write a time wrapper so I can unit test it. Mind is also an abstract class..

  • @ivanbanov8939
    @ivanbanov8939 Год назад +1

    They have also added a class called FakeTimeProvider to Microsoft.Extensions.Time.Testing which makes mocking a lot easier.

  • @AftercastGames
    @AftercastGames Год назад +1

    This is pretty similar to what I do already. Although I take a much simpler approach and have one source class for all of my time related events, and I have multiple classes that listen to those events and then notify other classes that they need to perform specific functions. No interfaces necessary.

  • @diadetediotedio6918
    @diadetediotedio6918 Год назад +14

    What we need now is a abstraction layer for file system, it would make possible some very interesting things like some tests for file system operations

    • @bomret
      @bomret Год назад +9

      There already is System.IO.Abstractions

    • @adrian_franczak
      @adrian_franczak Год назад

      @@bomret isnt this 3rd party lib?

    • @bomret
      @bomret Год назад +2

      @@adrian_franczak yes. But it’s been around for more than a decade and is very widely used.

  • @petrzurek5713
    @petrzurek5713 Год назад +6

    The best channel for .NET enthusiasts, keep on going mate 🦾

  • @brucerosner3547
    @brucerosner3547 Год назад +1

    Much ado about about the obvious. Over 30 years ago I was writing business programs in Fortran. It was clear then that the date and time printed on business reports sometimes need be independent of the current computer clock. Viola write a layer to provide times. I'm sure there is some "gang of four" jargon for this approach but it is something any decent programmer should know intuitively.

  • @Vespura_
    @Vespura_ Год назад +4

    Please make a video about datetimeoffset!

  • @xq_nemesis
    @xq_nemesis Год назад +2

    Please make a video on why to use DateTimeOffset ❤

  • @truman5652
    @truman5652 Год назад +1

    The main bug with time - it's how the time was implemented in real world. I mean timezones and local times. All of us have common time and we need to use one time for all areas of the world, then million of time issues will be solved. Morning, Day, Evening, Night will have own time range for each area, but time should be equal in any point of the Earth.

  • @Kirides
    @Kirides Год назад +4

    using an abstract class allows them to add more and more methods to the TimeProvider without breaking all existing software unlinke an interface.
    its the same with DbConnection vs IDbConnection.

    • @nickchapsas
      @nickchapsas  Год назад +5

      But that's why they added default implementations in interfaces in C# 8

    • @Kirides
      @Kirides Год назад

      @@nickchapsas default interface implementations allow for "multiple inheritance" and are limited to only function if the caller explicitly invokes the methods on the interface, you can't use them on the concrete types that implement the interface

    • @Ju57u5
      @Ju57u5 Год назад

      ​@@nickchapsas I think those don't work because they are planning to ship it down level.

  • @diadetediotedio6918
    @diadetediotedio6918 Год назад +1

    I was using an interface with basically the same name of .NET 8, it was ITimeProvider, in general I think interfaces can be better but an abstract class is still valid

  • @antonmartyniuk
    @antonmartyniuk Год назад +1

    It also took them 20 years to create a file-scoped namespaces. This tiny little code formatting feature should have been done like 10 years ago

  • @Bliss467
    @Bliss467 Год назад +1

    I generally prefer using minus operator for getting elapsed time so I’d like to see that with the timers but since c# requires operators be defined statically you wouldn’t be able to mock it ☹️

  • @tomheijtink8688
    @tomheijtink8688 Год назад +2

    I had rather that they created their own nodatime variation. Even with a type to store time zone and version and hook it up with EF core to make some geolocation based time calculations. It’s quite a lot of work to maintain and a consistent code base with different time zones and versions.

    • @quetzalcoatl-pl
      @quetzalcoatl-pl Год назад

      Yeah. And most probably that's exactly why they did not.

  • @jcmorin2007
    @jcmorin2007 Год назад +1

    I agree that it should be an Interface!

  • @pawefelcyn2119
    @pawefelcyn2119 Год назад +1

    Please, make a video about why we should use DateTimeOffset

  • @stoorps
    @stoorps Год назад +2

    They probably used an abstract rather than an interface with default implementations for backwards compatibility with netstandard2.0, which doesn't support default implementations for interfaces.

  • @sajagjain7169
    @sajagjain7169 Год назад +4

    Why should we use date time offset? Can you please make a video?

    • @adrian_franczak
      @adrian_franczak Год назад

      its important if your app is dealing with different timezones and storing everything as UTC will be confusing for user (summer/winter time)

  • @TheMasonX23
    @TheMasonX23 Год назад

    Why DateTimeOffset? Love the videos, thanks for the great content!

  • @TuxCommander
    @TuxCommander Год назад

    Please consider your (maybe our) wish for an ITimeProvider interface.
    If they do it, this will obsolete all our nice homebrew stuff.
    The timeprovider is nice, but I'll stay with my custom interface for now.
    At least we can note that they addressed the issue.

  • @harriehausenman8623
    @harriehausenman8623 Год назад +6

    This has never been a problem in any big consulting firm:
    Just test it 3 times a day! 🤣
    jokes aside: thanks for the update, great video as usual 🤗

  • @abdifatahAnnaati
    @abdifatahAnnaati Год назад

    When it comes to DateTime, every language/Framework out there has it's own ups & downs. I usually depend on My won Custom Class/Interfaces/Services but it a bit confusing/Tidy/messy sometimes and When I opened this video I was honestly expecting an Interface(ITimeProvider) instead of an abstract class but hey it's a good progress still I guess and the team should be made aware of this.

  • @tanglesites
    @tanglesites Год назад +1

    That’s cool. But passing the frequency in, doesn’t that make it system dependent as well? Or did I did not understand that right? Awesome content. As always.

  • @yurii1111
    @yurii1111 Год назад +1

    It feels that this provider lacks the interface segregation principle. It contains several different features that may be split into multiple interfaces. From the usage perspective it will be much more obvious, as now it looks similar to a service locator (anti-?)pattern.

  • @davidreis5086
    @davidreis5086 Год назад

    Please make a video explaining why you think they made an abstract class, and why they should be using interfaces for that!

  • @tevolutionYT
    @tevolutionYT Год назад +1

    Did you ask this question to chatgpt!! As far I remember you did!! And your reaction was out of the world!

    • @nickchapsas
      @nickchapsas  Год назад +1

      Yeap, that was part of the test that ChatGPT solved!

  • @adamding3873
    @adamding3873 Год назад

    I agree that it should be an interface. If the system doesn't provide it, for my own newly development projects, I would use a custom time provider interface.

  • @quetzalcoatl-pl
    @quetzalcoatl-pl Год назад

    ITimeProvider interface. Cool. Finally a standard one for basic uses. But I'm absolutely shocked that they introduced TimeProvider class (ok, let's have a handy default impl) with STATIC getters wired to system time AGAIN. Holy cow, what for? Those who currently use hard-wired system time, once they hear "the new TimeProvider is better, please do use it instead", they're going to use the static getters as they are accustomed to, gaining literally nothing. It's a goddamn FifthElement's BigRedDontPressMeButton. You just don't add old broken features under bunch of new names if you want to fix your library and want your users to learn to do better. D'oh!

  • @awmy3109
    @awmy3109 Год назад +2

    Why is generate greeting not taking the date time as a parameter?
    I don't use DateTimeOffset because I convert all dates to UTC in my systems before storage and all processing and computation is done in UTC. Conversion to local time is only done during presentation in the UI. DateTimeOffset is only needed when you want to store time with an offset that is not zero. UTC's offset is zero.

    • @nickchapsas
      @nickchapsas  Год назад +3

      So you don’t care about the user’s offset from utc? For example when you wanna email all users during their morning hours to improve email opening rates, how do you know what is "morning" for them when there is no UI or client? Storing everything is UTC out of context is naive

    • @awmy3109
      @awmy3109 Год назад

      @@nickchapsas I store the user's actual desired timezone in a database field that they can always change later. That's what I use to accept datetime from them and convert to UTC using TimeZoneInfo.ConvertTimeToUtc()
      before saving. Also when displaying, or doing something like the email you talked about, I use their stored timezone to convert from UTC to their desired timezone.
      One major advantage of converting to UTC before saving in database is that you are never affected by daylight savings changes. Also computation or filtering data based on time is easier because they are all stored in UTC.

  • @proosee
    @proosee Год назад

    TBH this should be a standard thing to provide interface for a class. The hell, make it part of the language, like if I have class Foo, then I have e.g. Foo.interface. I can't even tell how much time I *wasted* (yes, it is a waste) to write those wrapper classes just to be able to abstract from framework or some referenced library logic.

  • @dreamglimmer
    @dreamglimmer Год назад +1

    let them fix/simplify that working with client(saved peer user/taken from request) timezone, instead relying on assumption that client cares if it's afternoon on server or not..

  • @michaelconrad2690
    @michaelconrad2690 Год назад +1

    So, it looks like this would not stop someone on your project calling DateTime.Now. Are you aware of any analyzer, or similar, which could make sure everyone uses the new abstraction? I was thinking the other day about making an analyzer which can do that. Though its only the DateTime.Now and things like the methods on File which seem like clear targets for something like that.

  • @JonnyWideFoot
    @JonnyWideFoot Год назад

    I've been coding dotnet professionally since 1.1. In every one of my projects I've added an ITime with a default implementation returning utcnow. I've never understood why Microsoft refuse to provide this common mockable interface. It's simple...

  • @phizc
    @phizc Год назад

    They should make *ITimeProvider* a d have *TimeProvider* implement it. That way it would be easy to make a mocked implementation of the interface. This will be moot when roles and extensions/shapes get added though, since then you can just define the shape/interface you need after the fact.
    I *really* hope it's coming un 8.0, but I'm not holding my breath..

  • @BlazorPlate
    @BlazorPlate Год назад

    Can we use TimeProvider as scoped service instead of singleton?

  • @verzivull
    @verzivull Год назад

    I've seen some ways to solve it by using MS test shims. Which is of course are working in enterprise environment. I usually use my own interface for DateTime... But the need to test such scenario with DateTime is happening not very often

  • @Detyrious
    @Detyrious Год назад +1

    I'm a total und utter noob in C# (and programming) and just starting to learn, but wouldn't the "dateTimeNow" object be 'tightly coupled' with GenerateGreetText, something one should avoid, and I should inject a DateTime object with the time of the greeting I want? So I can mock it in the test? Like I said, I just learn C# via RUclips and I have no idea what I'm doing.

    • @flying-eagle-method
      @flying-eagle-method Год назад

      Your instinct is correct. Logic that works on time should be separated from code that gets the time.
      In a more complex scenario, however, that does multiple steps with delays and timeouts, having a mockable time interface that speeds up time is helpful.

  • @DummyFace123
    @DummyFace123 Год назад

    But yeah I’ve convinced every company I’ve worked in the past 10 years to used an IDateTimeProvider instead of DateTime static directly. Easy sell, there’s no other way to reliably unit test time dependent logic

  • @DanielAWhite27
    @DanielAWhite27 Год назад

    I’d love to see the stopwatch type take one of these in as a constructor so you could test your code with a stopwatch

  • @mattwatsonkc
    @mattwatsonkc Год назад +1

    This is the perfect example of something to never unit test at all. Very simple code that doesn't need testing. If you even did, you could have just passed in date times with specific times to test and never used a time provider.

  • @ashutoshkushawaha6664
    @ashutoshkushawaha6664 Год назад

    Hello TimeProvider is not available in visual studio 17.6 preview 2, What can I do to bring in my project?

    • @nickchapsas
      @nickchapsas  Год назад +1

      Download preview 4

    • @ashutoshkushawaha6664
      @ashutoshkushawaha6664 Год назад

      ​@@nickchapsasI found Preview 1 and Preview 2 for Visual Studio 17.6, but I'm looking for a download link for Preview 4. Could you please provide a link or direct me to a trusted source where I can download it? Thank you.

    • @ashutoshkushawaha6664
      @ashutoshkushawaha6664 Год назад

      @@nickchapsas I was able to find Preview 1,2 and Preview 3 for Visual Studio 17.6, but I'm looking for a download link for Preview 4. Could you please provide a link or direct me to a trusted source where I can download it? Thank you

  • @Alexvilg
    @Alexvilg Год назад

    Would it be better to inject a delegate to this method which could provide a datetime?

  • @rjpajaron
    @rjpajaron Год назад

    Can I have written version of this video? I have a hard time with DateTime handling.

  • @benjamininkorea7016
    @benjamininkorea7016 Год назад +1

    Not gonna lie. I've never seen a need to unit test time of day.
    Very interesting solution to a problem I never really worried about. :D

  • @lukegordon4734
    @lukegordon4734 Год назад

    Pretty shocked they went an abstract class route. Hopefully they do go w/ an interface approach

  • @ryan-heath
    @ryan-heath Год назад

    Why is the stopwatch functionality put into the timeprovider?
    When would you mock the stopwatch?

    • @nickchapsas
      @nickchapsas  Год назад +1

      If you’re using it to measure something and that measurement is part of something like a log parameter and you need to verify it

  • @Thorarin
    @Thorarin Год назад

    I kind of hate the clock abstraction they made. So bad I'm tempted to keep using my own or NodaTime.

  • @jameshancock
    @jameshancock Год назад

    Yes it should be an interface with default implementations on the interface.

  • @timseguine2
    @timseguine2 Год назад

    Ugh. TBH this doesn't really change much for me, since I have a design rule to only ever mock interfaces and never concrete or abstract types. I know that sounds a bit dogmatic, but I'd rather have a slight bit of mess in a trivial wrapper than risk having weird test code.

  • @sachinjangir166
    @sachinjangir166 Год назад +1

    make a video on datetime and datetimeoffset pls

  • @retokaderli9010
    @retokaderli9010 Год назад

    For e.g a REST API... can time provider be the client time (zone)?

    • @nickchapsas
      @nickchapsas  Год назад

      Depends on how you use it but yeah you can set a LocalTimeZone as long as you have the user’s offset from UTC

  • @parlor3115
    @parlor3115 Год назад +2

    @Nick, do you have plans just in case the AI takeover happens within the next couple of years? Like do you have an alternative career path or a lucrative non-tech side project in case this happens in the short term?

    • @nickchapsas
      @nickchapsas  Год назад +20

      I’m finally gonna start my dream beekeeping business

    • @rafekemmis3097
      @rafekemmis3097 Год назад

      @@nickchapsasStart now to corner the AI bee market!

    • @bomret
      @bomret Год назад

      You could use the swarm intelligence of the bees as your AI 😄

    • @vasiliyfofanov2605
      @vasiliyfofanov2605 Год назад

      @@nickchapsas Cool! Maybe you have another RUclips channel about it?

    • @proosee
      @proosee Год назад

      In complex scenarios the reason why Dapper is faster is because you are using SQL, a native language for your database engine - the example in video is where compiling a query takes more time than fetching data, in contrary, for complex queries the opposite happens: compilation of the query is fast, but the query itself is complex, so database engine takes time to process it, then other factors comes to place, mostly that you are using LINQ, so some things might be "lost in translation" when EF is compiling to SQL.
      I made this error only once, I spend enormous time to optimise LINQ for complicated query with some minor success and then I just downloaded Dapper, wrote it in SQL and it just worked few times faster (BTW, we were still using EF everywhere else, it's too convenient, Dapper was only for report-like complicated queries). My mistake was that I was using wrong tool to solve the problem - SQL is a language that was specifically designed to deal with querying data, there is no reason to make your life difficult for purity sake.

  • @local9
    @local9 Год назад +2

    Finally, hopefully over time this will improve now its finally here.

  • @simongeering
    @simongeering 10 месяцев назад

    Good grief I'll stick with my own IDateTimeProvider that takes 1 line to mock for the default common utcnow use case

  • @robertsilver1296
    @robertsilver1296 Год назад +1

    Sorry, someone is going to have to explain to me the difference between this video and just, in the tests, putting DateTime(2023, 01, 01, 8, 0, 0). I can’t see the difference because the video is not explaining in detail where it’s getting it’s time from.

  • @RudiOnRails
    @RudiOnRails Год назад +1

    If you decide to do a DateTime video please consider looking at something like NodaTime in that same video. Would be interesting to see if nodatime is really required.

  • @LaheralHaake
    @LaheralHaake Год назад

    Definitely should be an interface. Who knows, maybe they change it in the future

  • @11r3start11
    @11r3start11 Год назад

    Seems like interfaces are default and the most "expected" way to abstract things, espesially for external consumers.
    So I really dont uderstand why they "expose" abstract class, with this silly ticks parameter)

  • @bsoter
    @bsoter Год назад

    Finally I can remove all my IDateTimeProvider interface usage and substitute it with .NET native interf... oh, wait... an abstract class?

  • @DamienSawyer
    @DamienSawyer Год назад

    I think I'll still use Nodatime

  • @damiantedrow3218
    @damiantedrow3218 Год назад +1

    It looks to me like test induced design that offers no benefit for production code. Maybe someone can reply with an example of how this helps a real world scenario to change my mind.

  • @albe1620
    @albe1620 Год назад

    It's little confusing that they added the stopwatch features to it. Why not using them directly over the Stopwatch class?

    • @CraigologyAustralia
      @CraigologyAustralia Год назад

      That was my thought too, seems like unnecessary duplication of the framework surface area.

  • @fifty-plus
    @fifty-plus Год назад

    I think I'll stick with Noda and IClock.

  • @jazzweather
    @jazzweather Год назад

    I don't understand why one couldn't just create a DateTime object instead of using system time and pass it to the test cases.

  • @DummyFace123
    @DummyFace123 Год назад

    Lol you just answered your own question for why it’s an abstract class and not an interface, the high frequency stuff

  • @daniilchertkov2067
    @daniilchertkov2067 Год назад

    And solution looks like addon of stopwarch...still raw solution, so we have to expect different implementaion after sometime ...looks like

  • @terminator4974
    @terminator4974 Год назад

    I always dislike the fact there are no interfaces. I mean its 2022 decoupling is mandatory i never inject an intstance always an interface and the exception to the rule is third party instances only when i can mock them easily in unit test. If not they will get abstracted away behind a concrete implementation of own with an exclude from codecoverage attribute. Very bad but at least i control my own interaction with the 3rd party code.

    • @adrian_franczak
      @adrian_franczak Год назад

      sometime interfaces are useless - "abstraction hell" and errors in runtime, in most cases you have only one implementation and interface is only used for testing but it can be solved differently

    • @terminator4974
      @terminator4974 Год назад

      @@adrian_franczak i get your point but it doesnt mean interfaces are a way to abstraction hell and not are useless when you only have one concrete class implementing the interface. If you want to swap out the old implementation for the new one you get rekt with your hard dependencies and your "ugly" way of testing your own implementation interacting with the 3rd party library

  • @pilotboba
    @pilotboba Год назад +1

    I was so hoping you would say Dotnet was removing null. :)

  • @lordicemaniac
    @lordicemaniac Год назад

    so why utcnow instead of now?

  • @josephmathes
    @josephmathes 12 дней назад

    Dude, there's never been anything stopping you from using dependency injection.

  • @antibioticaddict
    @antibioticaddict Год назад

    Why could this all of not been done in an interface?

  • @peterkitts8815
    @peterkitts8815 Год назад

    Please tell me about DateTimeOffset

  • @HakunaMatata225
    @HakunaMatata225 Год назад

    Trivial problem, and trivial unit test....!!!

  • @ecblanco
    @ecblanco Год назад

    Comment to remind you DateTimeOffSet Video. Cheers.

  • @anon0
    @anon0 Год назад

    they shouldve named it timeservice

  • @Rose-ec6he
    @Rose-ec6he Год назад +1

    Yayy new nick upload!

  • @BernhardMillauer
    @BernhardMillauer Год назад

    My IClock implementation is much better. Based on an interface, default service calls DateTime.* and if I want, I can TimeTravel in my unit tests in the TestableClock instance. Microsoft did it again, wrong.

  • @obinnaokafor6252
    @obinnaokafor6252 Год назад

    Well done, Microsoft.

  • @denm8822
    @denm8822 Год назад +4

    Oh, inject this, inject that... In a blink of an your constructor becomes total mess

    • @rafekemmis3097
      @rafekemmis3097 Год назад

      You can always just resolve it using the IServiceProvider when you need it.

    • @diadetediotedio6918
      @diadetediotedio6918 Год назад

      Lmao

    • @diadetediotedio6918
      @diadetediotedio6918 Год назад +2

      Use a source generator if this is a great problem for you, or better, split your code better and not create so powerful classes

    • @JerryFederspiel
      @JerryFederspiel Год назад +3

      If your constructor is taking a lot of dependencies, your class is probably doing too much. If your constructor is a mess, that also suggests that the constructor itself is doing too much. Ideally, a constructor should just get the object in a valid state so it can start taking method calls; often that just means assigning the dependencies to fields.

  • @MrHeavyRunner
    @MrHeavyRunner Год назад

    What's wrong with having DateTime as parameter and using DateTime new() or .Parse in test to run it? There you get consistent results. Omg what is this video even about...

  • @alirezanet
    @alirezanet Год назад

    ahh I don't like it, IDateTime interface would be much nicer

  • @DxCKnew
    @DxCKnew Год назад

    The more everything become more abstract/interfaces and dependency-injected, the more over-complicated and over-engineered the code seem to me.

  • @NotACat20
    @NotACat20 Год назад

    Bullshit twice. TimeProvider is just mix everything in single interface, but them should not. Places where you need QPC is strictly not places where you need wall clock and measure units is different.

  • @terminator4974
    @terminator4974 Год назад

    Im just wondering why u use nsubstitute instead of moq. Thanks for this great video :)