OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
854 stars 476 forks source link

[feature/netcore] It's not possible anymore to override SelectController-method #1377

Closed Compufreak345 closed 6 years ago

Compufreak345 commented 6 years ago

I am currently trying to add a generic controller to the Odata-Routing. Regarding to this stackoverflow-post it should be possible to create a custom RoutingConvention and override the SelectController-method - unfortunately this method was removed in the feature/netcore-branch and I have a really hard time finding an alternative approach.
I tried overriding the path in the RouteContext but I got stuck at trying to inherit from NavigationSourceRoutingConvention and create an ODataPathSegment as the constructor that I probably need is marked internal. Is there any way to do something like this using the current feature/netcore-branch or is this not possible?

Assemblies affected

OData WebApi lib 7.0.0-Nightly201804051241

Reproduce steps

Try to implement this code:

public class CustomControllerRoutingConvention : IODataRoutingConvention
{
    public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
    {
        return null;
    }

    public string SelectController(ODataPath odataPath, HttpRequestMessage request)
    {
        return "SomeFixedContrllerNameWithoutTheControllerSuffix";
    }
}

Expected result

I can override the SelectController-method to change the controller, or have another way to implement a default controller if no specific controller is found.

Actual result

There is no SelectController-Method in the interface.

Additional detail

When comparing the files here with the files here you can see that the SelectController-method got removed.

Any help is greatly appreciated.

Thanks & best regards, Christoph

robward-ms commented 6 years ago

AspNetCore does not have a SelectController method anymore so the IODataRoutingConvention interface does not either, only a SelectAction method.

Here is an example of an IODataRoutingConvention in the E2E tests.

If you want to derive from NavigationSourceRoutingConvention, take a look here for an example of overriding SelectAction while leveraging the SelectController semantics in NavigationSourceRoutingConvention.

biaol-odata commented 6 years ago

@Compufreak345 Please let's know whether you have successfully applied the new aspnetcore.odata alternative above and get your issue at hand resolved. Thanks.

Compufreak345 commented 6 years ago

@biaol-odata We unfortunately already have changed our approach to use seperate (empty) controllers that inherit from a base-controller instead of using the generic approach before this issue was answered, so we did not try the alternative until now. I'm currently not working on this project anymore, I'll pass this issue to a colleague if they want to change the approach in the future. I'll close the issue for now.

Thanks & best regards, Christoph