Aspnet-api-versioning: Support for OData with .netcore 3.0

Created on 28 Oct 2019  路  8Comments  路  Source: microsoft/aspnet-api-versioning

I noticed that in your version 4.0 branch you have added .netcore 3.0 support, but the OData examples are not updated. Is that because they are not supported or won't be supported?
If they will be supported are you open for a pull request? I may need a little guidance on how to implement but am willing to help out.

app.UseMvc( routeBuilder =>
                {
                    // the following will not work as expected
                    // BUG: https://github.com/OData/WebApi/issues/1837
                    // routeBuilder.SetDefaultODataOptions( new ODataOptions() { UrlKeyDelimiter = Parentheses } );
                    routeBuilder.ServiceProvider.GetRequiredService<ODataOptions>().UrlKeyDelimiter = Parentheses;
                    routeBuilder.MapVersionedODataRoutes( "odata", "api", modelBuilder.GetEdmModels() );
                } );

Should be replaced with something like:

app.UseEndpoints( endpoints=>
            {
                endpoints.MapVersionedODataRoutes( "odata", "api", modelBuilder.GetEdmModels() );

            });

edit: Just saw that this is blocked by OData WebApi not yet supporting .netcore 3.0
https://github.com/OData/WebApi/issues/1748

answered asp.net core external odata question

Most helpful comment

@stormleoxia, Endpoint Routing will be supported when there is _some_ stable, public release. I don't have the capacity or resources to _chase_ nightly builds. I've stressed that the OData team should be considering the required _hooks_ and extension points to make things easier for things such as API versioning, but we'll see what they'll do. They have not re-engaged or otherwise opened any new dialog regarding their designs or plans.

Historically, I've had to go completely through their routing codebase and reimplement or replace a bunch of infrastructure to make sure things all work together. Hopefully, that won't be the case this time. I suspect basic routing support will be available before the API Explorer support for things like Swagger/OpenAPI.

For now, I'm just keeping an eye on the issues and discussions. The community has been quite vocal and I'm happy to continue engaging.

Thanks

All 8 comments

You got it. OData doesn't support .NET Core 3.0 so there is no way to for API Versioning to support it. Unfortunately, it's out of my hands. I've done the work to multi-target ASP.NET Core 2.2 and 3.0. This will allow you use API Versioning 4.0 with OData, which will include the latest features and bug fixes, but there won't be any support for .NET Core 3.0 - obviously. It should be a trivial change once OData supports .NET Core 3.0.

Thanks

I can't do much about this, but it looks like the team is actively working on it. Hopefully, they have something out in the next couple of months. In the meantime, API Versioning 4.0 has been published. The package multi-targets so that you can use the latest and greatest with OData on ASP.NET Core 2.2.

Thanks

The OData Team pushed a nightly build which works in .net core 3. When I add your package and enable versioning with: EnableApiVersioning() the error comes back:

TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.Internal.ActionConstraintCache' from assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

Sorry for cross posting but after found this closed issue, I think you can help 馃槈

https://github.com/OData/WebApi/issues/1748

Any updates on how to do this since 7.3 is out of beta now? There was a blog post suggesting it would be coming out when 7.3 is out of beta? https://devblogs.microsoft.com/odata/experimenting-with-odata-in-asp-net-core-3-1/

Really looking to setup OData in Core 3.1 with Versioning, and it seems I have to use app.UseMvC

@nfgallimore versioning support for 3.1 already out and has been for a while. OData still doesn't support _Endpoint Routing_ so don't expect that to work. You don't need (nor ever needed) UseMvc because that just adds the UI aspects; UseMvcCore should be sufficient. You do, however, need to explicitly disable _Endpoint Routing_ just like you had to do in ASP.NET Core 2.2. I think everything else about the setup is exactly the same as before.

Hello,
As mentioned here (https://github.com/OData/WebApi/issues/2029),
Endpoint Routing is supported in the nightly build of OData.

I managed to make it work for one version but I suspect it would need some custom version of
ODataEndpointRouteValueTransformer to select the right api version.

Any plans to support Endpoint Routing for aspnet-api-versioning ?

@stormleoxia, Endpoint Routing will be supported when there is _some_ stable, public release. I don't have the capacity or resources to _chase_ nightly builds. I've stressed that the OData team should be considering the required _hooks_ and extension points to make things easier for things such as API versioning, but we'll see what they'll do. They have not re-engaged or otherwise opened any new dialog regarding their designs or plans.

Historically, I've had to go completely through their routing codebase and reimplement or replace a bunch of infrastructure to make sure things all work together. Hopefully, that won't be the case this time. I suspect basic routing support will be available before the API Explorer support for things like Swagger/OpenAPI.

For now, I'm just keeping an eye on the issues and discussions. The community has been quite vocal and I'm happy to continue engaging.

Thanks

@commonsensesoftware I've had to do the same - ie reading their codebase to reimplement some things (not the same order of magnitude of your work though) but it works now.

If you're interested, my work is in my fork of the repo on EndpointRoutingSupport branch.
My work is not perfect though as it may need some additional unit tests, and it doesn't replicate all the overrides of MapVersionedODataRoutes. If you have any comments or questions, please let me know.

Thank you for your great work by the way ;)

Was this page helpful?
0 / 5 - 0 ratings