Mostly brevity, which isn't a bad thing. They're just inconsistent with how everything, even other similar things, work which makes them confusing to many devs.
Hello Steve. Nice video. Great to see you directly on my homepage :) I do have 2 short real life usage questions tho, related to a current microservice hierarchy I am developing. Could primary constructors and records be used also for commands, queries and integration bus events or would it be better to just use classes and have the whole record as a record and not one containing references? And secondly would be, why use MassTransit when you can very easily (and more performing) use MediatR for local orchestration?
they are nice and i like to use them, but i dont understand why microsoft decided to make them mutable by default. i mean if the primary constructor parameters would always be readonly, i could still assign them to a mutable field or property when needed. instead of the other way around…
I agree that would have been an excellent decision, in hindsight. Probably they had reasons. I think they are looking into supporting readonly in C# 13.
Results are meant to avoid exceptions; guards throw exceptions. If you want to combine them, you'd need a try-catch in the method that returns Result and in the catch block you'd return Result.Error and provide some details there.
Hi Steve, Thank you for publishing the interesting video. However, the source code link is not working correctly. After clicking on the source code link, I was brought to a page saying, "Almost finished... We need to confirm your email address. To complete the subscription process, please click the link in the email we just sent you." Unfortunately, I haven't received any email (I've also checked the spam folder). Could you please look into this issue ? Thank you for your help
You mean something like: public class A(Product product) { private Product _product = product; public void DoSomething => _product.UpdateState(); } Will this change the product that was passed into the constructor? It will behave exactly as if you had a (normal) constructor and you passed in Product there.
@Ardalis not exactly. If you call product.update (the one from primary). Did this mutation also impacted _product field ? As they share the same ref, I am wondering what happens. (Mutation can also happens outside the class 😱)
Cool. Some good points there. I've only used them a couple of times and don't really understand what they bring to the table other than brevity.
Mostly brevity, which isn't a bad thing. They're just inconsistent with how everything, even other similar things, work which makes them confusing to many devs.
Hey Steve,
Great points around this topic, thanks for clarifying this feature, sometimes this sugar syntax can be messy.
Keep doing this great work 💪🏻
Thanks!
Hello Steve. Nice video. Great to see you directly on my homepage :)
I do have 2 short real life usage questions tho, related to a current microservice hierarchy I am developing.
Could primary constructors and records be used also for commands, queries and integration bus events or would it be better to just use classes and have the whole record as a record and not one containing references?
And secondly would be, why use MassTransit when you can very easily (and more performing) use MediatR for local orchestration?
they are nice and i like to use them, but i dont understand why microsoft decided to make them mutable by default. i mean if the primary constructor parameters would always be readonly, i could still assign them to a mutable field or property when needed. instead of the other way around…
I agree that would have been an excellent decision, in hindsight. Probably they had reasons. I think they are looking into supporting readonly in C# 13.
Question, how can we combine your guardclauses and results into a single pattern?
Results are meant to avoid exceptions; guards throw exceptions. If you want to combine them, you'd need a try-catch in the method that returns Result and in the catch block you'd return Result.Error and provide some details there.
Hi Steve,
Thank you for publishing the interesting video. However, the source code link is not working correctly. After clicking on the source code link, I was brought to a page saying, "Almost finished... We need to confirm your email address. To complete the subscription process, please click the link in the email we just sent you." Unfortunately, I haven't received any email (I've also checked the spam folder).
Could you please look into this issue ? Thank you for your help
Sorry it's not working for you. It seems to be working overall so I'm not sure what the issue is with MailChimp and your email account.
What happens with reference types mutation in method and property initialization ? Does it follow reference or is it safe ?
You mean something like:
public class A(Product product)
{
private Product _product = product;
public void DoSomething => _product.UpdateState();
}
Will this change the product that was passed into the constructor?
It will behave exactly as if you had a (normal) constructor and you passed in Product there.
@Ardalis not exactly. If you call product.update (the one from primary). Did this mutation also impacted _product field ? As they share the same ref, I am wondering what happens. (Mutation can also happens outside the class 😱)