aspnet-contrib / AspNet.Security.OpenIdConnect.Samples

ASP.NET Core samples demonstrating how to use the OpenID Connect server with MVC or JS apps
64 stars 31 forks source link

Question about the UseWhen extension method #7

Closed atrauzzi closed 8 years ago

atrauzzi commented 8 years ago

I've actually enjoyed similar functionality to the UseWhen extension method in other frameworks and languages, but I'm wondering...

Does the way it's implemented mean that you're rebuilding an entire new application pipeline for every request? Is there any risk of this being inefficient?

kevinchalet commented 8 years ago

Does the way it's implemented mean that you're rebuilding an entire new application pipeline for every request? Is there any risk of this being inefficient?

Actually, the branched pipeline is only built at startup time, thanks to the special Use overload that takes a Func<RequestDelegate, RequestDelegate>. The only part which is executed per-request is the request delegate itself:

return context => {
    if (condition(context)) {
        return branch(context);
    }

    return next(context);
};
atrauzzi commented 8 years ago

I love it. Thanks! :)

atrauzzi commented 8 years ago

@PinpointTownes I was just going through the docs.asp.net and noticed the Map method. Any differences between that and what you've made?

kevinchalet commented 8 years ago

https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/issues/137#issuecomment-141702228

atrauzzi commented 8 years ago

Ahh, I see. So if I used MapWhen vs UseWhen, I'd have to create two completely separate pipelines? So UseWhen is good if you want to DRY out the setup of pipelines?

kevinchalet commented 8 years ago

Yep.