C
C#2y 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
Pobiega2y ago
so it can be chained
joeystdio
joeystdioOP2y ago
of course 😄
Pobiega
Pobiega2y ago
some people really like to do
services
.AddSomething()
.AddSomethingElse()
.AddAthirdThing();
services
.AddSomething()
.AddSomethingElse()
.AddAthirdThing();
(I'm one of those people)
joeystdio
joeystdioOP2y ago
I never used chaining so didn't thought about that Yeah looks clean as well Thanks !
Tvde1
Tvde12y ago
this is often called the "fluent" or "builder" pattern https://dzone.com/articles/fluent-builder-pattern
Pobiega
Pobiega2y ago
it does break when you end up with the ones that return a specialized builder, like AddAuthorization etc
joeystdio
joeystdioOP2y ago
Yes 🙂
Thinker
Thinker2y ago
$close
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Pobiega
Pobiega2y ago
he did, we juist re-opened it by writing 😄

Did you find this page helpful?