Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@saddamhossaindotnet Жыл бұрын
I loved the way you explained it. Just simply awesome! Thanks for sharing this video, my friend!
@MilanJovanovicTech Жыл бұрын
Glad you liked it!
@ruekkart Жыл бұрын
At 11:31, it might be a good idea to check if FirstName and LastName (as Value Objects) are not null within the ChangeName method. While their inner "Value" property is assured to be non-null or non-empty, the objects themselves could still be null
@MilanJovanovicTech Жыл бұрын
Turn on "Nullable reference types" - the compiler will warn you if you try pass in a null. Otherwise, there is no chance that a null will make it to the domain.
@vincentjacquet2927 Жыл бұрын
@@MilanJovanovicTech Unfortunately, the compiler does not enforces it, neither on the caller or the callee side. So any code calling your function may pass in a null reference. Therefore you still must guard against null, even when Nullable reference types is turned on. But this is the only guard you still have to write. The value object with the more complete validation is a nice touch, even if I would have made a single PersonName with both firstName and lastName, as the two are tightly coupled.
@fifty-plus Жыл бұрын
Be careful in your example, connectionString wasn't an argument, your expectation was that it was set in the environment but you were guarding a side effect from that. Nice job suggesting the packages, much better than hand baking a lot of code. The new dotnet guards are a nice addition too.
@MilanJovanovicTech Жыл бұрын
What other way do I have to validate the environment?
@_iPilot Жыл бұрын
Explicit null check also suppresses all "possible NRE" warnings on using checked variable. Guard classes are hiding that check from the code analyzer, but attribute `[NotNull]` for value argument in method `IsNotNullOrWhiteSpace` can instruct analyzer that the string is fine when the Guard method does not throw an exception.
@MilanJovanovicTech Жыл бұрын
Yes
@TurgayTuerk Жыл бұрын
Thank you Milan. Very instructive as always.
@MilanJovanovicTech Жыл бұрын
Always welcome, glad you enjoyed this one :)
@kodindoyannick5328Ай бұрын
Awesome content! Thanks so much Milan!
@MilanJovanovicTechАй бұрын
My pleasure!
@aisonjackmendoza7709 Жыл бұрын
Little by little I'm learning new things and starting to understand how and why to use different techniques. Can I just ask, is it essential to implement eventhandlers for the domain?
@MilanJovanovicTech Жыл бұрын
It's not, but it's something I prefer using
@laviritel Жыл бұрын
I was wondering when I watched your pragmatic course, why you don’t use the guard clauses there. In our team, we are using ardalis library, and we check almost everything, even dependency services passed to constructor.
@MilanJovanovicTech Жыл бұрын
I like using guard clauses, but I prefer the result pattern more. It does make me wonder what is the point of some guard clauses. For example services from DI. When will they be null?
@pilotboba Жыл бұрын
The stack trace on that guard clause will point to the guard clause, correct? I assume the gaurdclause and throw library will cause the same thing. Also, i would prefer the result pattern for value object creation as well, which Vladimir Khorikov demonstrates in several of his DDD and Validation Fundementals courses on pluralsight.
@MilanJovanovicTech Жыл бұрын
Yes, they'll have the same stack trace. And I'm working on a Result pattern video soon :)
@mwaseemzakir Жыл бұрын
Loved it Milan❤
@MilanJovanovicTech Жыл бұрын
Awesome! 😁
@cclementson1986 Жыл бұрын
Defensive programming?
@MilanJovanovicTech Жыл бұрын
Yes it is
@cclementson1986 Жыл бұрын
@@MilanJovanovicTech Awesome! I love the promotion of defensive programming. Thanks for the tutorial. I do C++ and defensive programming is a must! Love to see it being implemented in other languages.
@sebastianszafran52213 ай бұрын
I know that it's a rather silly example, but FirstName and LastName still can technically be null, right? I don't see anything preventing from writting following code FirstName firstName = null; person.UpdateFirstName(firstName);
@MilanJovanovicTech3 ай бұрын
Nullable reference types can prevent code like that from compiling.
@porcinetdu6944 Жыл бұрын
I think that the evaluation of the param name for CallerArgumentExpression is done at compile time instead of at runtime. Not 100% sure
@MilanJovanovicTech Жыл бұрын
You are correct there!
@MilanJovanovicTech Жыл бұрын
Docs for reference: learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/caller-argument-expression
@darkopz Жыл бұрын
I’ll argue the Throw Extensions can cause confusion. It’s a bit of an oxymoron to dereference the connection object with a ThrowIfNull.
@MilanJovanovicTech Жыл бұрын
It's also less obvious what's going on versus the explicit guard approach
@manasabbi Жыл бұрын
How it's different from Fluent Validation, am i miss something here?
@MilanJovanovicTech Жыл бұрын
How are exceptions different from FluentValidation?
@winchester2581 Жыл бұрын
IMO FluentValidation is more fittable in complex scenarious when you need to validate complex objects. Guards just throw exceptions, behind the scenes it's just the same exception throwing. I see no reason to use it, for example, for extracting connection string because it's simple object and it's validated in one place
@andreyz3133 Жыл бұрын
sad thing is that if you using nullable reference types enabled, ide will treat variable as nullable and you have to use ! operator
@MilanJovanovicTech Жыл бұрын
There are ways to help the compiler 😁
@phisakel1 Жыл бұрын
Swift language has a native guard statement 😄
@MilanJovanovicTech Жыл бұрын
That's awesome. Got a link to some docs?
@NickSteffen Жыл бұрын
.NET has built in guard clauses now too. You can use ArgumentNullException.ThrowIfNull(value) for null checks. You can use ArgumentException.ThrowIfNullOrEmpty(stringValue) for strings. In .NET 8 they are adding a bunch of new ones as well under an ArgumentOutOfRangeException. The best part is that the null checks will resolve nullable reference compiler warnings whereas the make your own ensure class method does not as the compiler doesn’t recognize that as a null check.