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

Did you find this page helpful?