Check out my new “Integration testing in ASP .NET Core” course and use code INTESTING1 for 20% off (first 300): …
22 Comments
Leave a Reply
You must be logged in to post a comment.
Check out my new “Integration testing in ASP .NET Core” course and use code INTESTING1 for 20% off (first 300): …
You must be logged in to post a comment.
For those wondering, yes the required keyword IS coming in C# 11. It was demoed at Build and NDC Copenhagen and I confirmed it with Mads Torgersen himself
very nice feature.
I felt it when you showed the constructor where each line had a value to pass in required fields. I’ve been in that scenario far too many times. I was also in a bit of a pickle because the settings for our quality gate, SonarCloud, restricted the number or arguments for methods including constructors. So in the end I ended up resorting to “smuggling” arguments in a class solely built for passing all the arguments I needed. I do like the idea of transforming object initializers into de facto customizable constructors with the ability to declare required properties. I’ve been out of the loop for a while due to health issues so I’ve been enjoying catching up watching Nick. Thanks Nick!
I dunno, it just looks sugar to me… What was the problem with (overloading) constructors, again?
How would a class like that be handled when it's injected by an dependency injection?
Welcome to March 3, 2021 – Dart 2.12 =P
Not a fan, introducing another way to do the same thing with little benefit.
Excellent video! At time mark 5:00, what are you using to draw on your screen so quickly?
Nick – thank you for such a well explained video on the upcoming feature.
I like your videos.
And I like that you use allman braces. They're nicely readable for people with bad eyesight like me.
This could be used to avoid the picky behavior of EF core with entity that have ctor with parameters. Currently I just add a private parameterless ctor, but this could avoid writing any ctor at all
Meh. The 'Required' attribute is in System.ComponentModel.DataAnnotations
People skip unit testing in favor of integration testing because they are mediocre developers at best
Any chance on getting a new discount code 🙂
All is nice and dandy by most of your videos could fit in 1-2 mins of total time. How come this vide ended up having 9:30 mins I have no idea…
I just hope this works well with JSON serialization. That requires a parameterless constructor for deserialization anyways most of the time, so the required keyboard spares me a lot of checking code. I appreciate it immensely. And I also also highly appreciate the work you're doing with Videos and courses.
what if i need to run a class method to initialize a property? i would normally run it in the constructor and assign its return value to the property but like this, without a constructor, i'd have to delegate that to an external method in order to call it during initialization. maybe this will come in handy for a few scenario but constructors will still be needed for complex inits
Cool, something that I could never do before is now actually possible :). I wrote my own DI Container long time ago that uses MEF-like attributes and field-injection and I got massive problems with nullable-reference types. BTW, I love attributes because they tell me exactly how a class plays a role in the infrastructure in comparison to other DI DI containers where I have no clue whether the class should be manually instantiated or retrieved from DI container, I imidiatelly see what dependencies a class has, I don't need to use constructor and extra code to set the fields, and I don't need to register each class. For instance:
[Export]
public class C
{
[Import]
private D dependency;
}
I got warnings that property is not nullable but is also not initialized directly in code. I don't want it to be nullable because it is not optional and DI container will throw an error while bootstrapping the application if dependency is missing. Using "required" keyword could solve this big problem.
[Export]
public class C
{
[Import]
private required D dependency { get; init; }
}
I would have to use private properties instead, but it's fine and not much more code to write. But I need to experiment with the feature if it would actually work.
I really like that they're adding more tools for api/tool code to demand correct usage through compiler errors rather than runtime errors, that's the most powerful thing a compiled language can do to help us
This is OK for POCO classes, but what if I don't want string property to have empty string, or I need to perform some specific domain validation. So in the end ctors or static factory methods are still way to go.
Setting a full name to be immutable might not be a good idea , what if the person changers his/ her first name ( fir any reason including but niot limited to sex change)?
My only question is if this will work with dependency injection