C
C#10mo ago
joeystdio

✅ Why return IServiceCollection in an extension method?

Is there any reason why not to make the method void instead?
No description
10 Replies
Pobiega
Pobiega10mo ago
so it can be chained
joeystdio
joeystdio10mo ago
of course 😄
Pobiega
Pobiega10mo ago
some people really like to do
services
.AddSomething()
.AddSomethingElse()
.AddAthirdThing();
services
.AddSomething()
.AddSomethingElse()
.AddAthirdThing();
(I'm one of those people)
joeystdio
joeystdio10mo ago
I never used chaining so didn't thought about that Yeah looks clean as well Thanks !
Tvde1
Tvde110mo ago
this is often called the "fluent" or "builder" pattern https://dzone.com/articles/fluent-builder-pattern
Pobiega
Pobiega10mo ago
it does break when you end up with the ones that return a specialized builder, like AddAuthorization etc
joeystdio
joeystdio10mo ago
Yes 🙂
Thinker
Thinker10mo ago
$close
MODiX
MODiX10mo ago
Use the /close command to mark a forum thread as answered
Pobiega
Pobiega10mo ago
he did, we juist re-opened it by writing 😄