简体   繁体   中英

How to register OData extension methods in .NetCore 3.1 outside of UseMvc middleware

After migrating my API from .net core 2.2 to 3.1, I am facing some issues to decide which is the best approach I should follow to register OData extension methods for my API. Currently, I have this code

public void ConfigureServices(IServiceCollection services)
 {
          ....
             #region OData

            services.AddOData();

            #endregion  
          ....
 }

On the Configure method

public void Configure(IApplicationBuilder app, IHostEnvironment env)
 {
  ...
  app.UseAuthentication();
  app.UseMvc(routeBuilder =>
                        {
                            routeBuilder.Select().OrderBy().Filter().MaxTop(1000).Count();
                            routeBuilder.EnableDependencyInjection();
                        });
   ...
 }

How can I register Select() OrderBy() Filter() .... using the following approach? Is this the right way to do it, without registering UseMvc?

 public void Configure(IApplicationBuilder app, IHostEnvironment env)
 {
        ...
        app.UseRouting();
        app.UseAuthentication();
        app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            ...
 }

Check this article out: Experimenting with OData in ASP.NET Core 3.1 .

Apparently .NET Core 3.0 and 3.1 don't support OData yet. You can, however, use the beta version, the steps for which is explained in the article.

Update:

They do support OData as of version 7.3.0. However, they cannot be used with endpoint routing yet. You can follow this Github thread for updates, in particular, this answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM