aspnet / Routing

[Archived] Middleware for routing requests to application logic. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
272 stars 122 forks source link

Question about endpoint routing and multitenancy #904

Closed dazinator closed 6 years ago

dazinator commented 6 years ago

Reading this:

Since routing builds a graph based on the endpoints, this means that the complexity of the tree scales very directly with your usage of features. from https://blogs.msdn.microsoft.com/webdev/2018/08/27/asp-net-core-2-2-0-preview1-endpoint-routing/

With traditional routing, you can fork the http middleware pipeline, for example, per tenant, and then on each fork of the pipeline you can UseRouting with a router configured with routes for the specific tenant. This provides nice isolation of tenant routes.

What's the story with EndPoint routing in terms of having per tenant route tables / graphs? Will this concept still apply?

mkArtakMSFT commented 6 years ago

Thanks for contacting us, @dazinator. @JamesNK, can you please look into this? Thanks!

JamesNK commented 6 years ago

Hi

Do you mean forking the pipeline using Map? If so then this is supported:

app.Map("/Branch1", branch =>
{
    branch.UseEndpointRouting(routes =>
    {
        //
    });
});

app.Map("/Branch2", branch =>
{
    branch.UseEndpointRouting(routes =>
    {
        //
    });
});
dazinator commented 6 years ago

Thanks for the clarification, looks like that should cater for different tenants having different endpoints.

dazinator commented 6 years ago

Just occured to me, to extend the question a little, where / how would mvc's attribute routing fit into your endpoints example above?

JamesNK commented 6 years ago

Like this:

app.Map("/Branch1", branch =>
{
    branch.UseEndpointRouting(routes =>
    {
        routes.MapMvcApplication(); // registers attribute routed MVC actions
    });
});

Do you have UseMvc nested inside Map today? Could you give a simplified example? e.g. the startup.cs code related to branching and MVC, along with example URLs.

JamesNK commented 6 years ago

I was paranoid that we have never tested endpoint routing in branching. Test to confirmed it works - https://github.com/aspnet/Routing/pull/905 😸

dazinator commented 6 years ago

Thanks for the test coverage :-) In the test, I noticed the additional call to app.UseEndpoint(); - wondered why you need to UseEndpoint and UseEndpointRouting?

JamesNK commented 6 years ago

UseEndpointRouting = matching endpoint UseEndpoint = execute endpoint

dazinator commented 6 years ago

Not sure if you need this, but I fork the middleware pipeline slightly differently, not using Map, as seen here: https://github.com/dazinator/Dotnettency/blob/develop/src/Dotnettency.AspNetCore.MiddlewarePipeline/DelegateTenantMiddlewarePipelineFactory.cs#L27

However I think it should be similar conceptually. There is a sample app that can be run in the same repo showing multitenant app in action. I'll close this for now as my question is answered (thanks).

dazinator commented 6 years ago

UseEndpointRouting = matching endpoint UseEndpoint = execute endpoint

got ya, cheers