Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Drum in BaseController<T> to allow generic route references #16

Open
LandryDubus opened this issue Oct 9, 2019 · 2 comments
Open

Comments

@LandryDubus
Copy link

I am using a custom DirectRouteProvider that overrides the GetActionRouteFactories method of the DefaultDirectRouteProvider in order to allow inheritance in attribute routing.

This allows me to use attribute routing in a BaseController to define route for every action that should be available to all the inheriting controllers (TestController : Basecontroller).

This works fine until I try to generate links to generic routes.

I can't name the routes dynamically based on the generic type as this is not allowed in attributes in C#.

I can't define a name for these routes as there would be many routes with the same name (for all inheriting controllers).

I thought I could use your package as Drum works well with unnamed routes, but I can't seem to find a way to use the uriMaker from inside the BaseController to reference the route from the inheriting controller in a generic way.

Is there a way out?

@anaximander23
Copy link

This pull request might be of interest. Does that look like it would solve your problem?

@LandryDubus
Copy link
Author

Thanks for your reply.

But i don't see how this helps me resolve my problem.

What I want is to get a link for a route defined for an action of a web api controller in a inherited BaseController type.

For instance, here is a derived controller:

[RoutePrefix("api/test")]
    public class TestController : BaseController<TestCustomType> { }

Here is the base controller:

public class BaseController<T> : ApiController where T : CustomType
    {
        [Route("")]
        public T Get()
        {
            return new TestCustomType();
        }

what I want is to be able to get a link to the Get action of TestController from within the code of the Basecontroller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants