Git Product home page Git Product logo

Comments (3)

commonsensesoftware avatar commonsensesoftware commented on July 20, 2024 1

I was trying to find the release notes on this, but I'm not finding them. UseApiBehavior was introduced to support backward compatibility for <= 2.1. It was originally false and later defaulted to true. It was always to slated to be removed at some point. I think that happened in 6.0 and I just forgot to call it out.

The first question is how you are using UseApiBehavior. If you're explicitly setting it to true, that's the default and current behavior. There's nothing for you to do. You're migrated. 😄

If you're setting it to false, that still exists, but is unusual. The entire point of UseApiBehavior was to make it easy to filter API controllers. Setting the configuration value to false implies that you are using API Versioning for non-API controllers. This is supported for people that want to do that, but is a bit of an odd case.

At the same time that UseApiBehavior was introduced, two new services were also introduced:

  • IApiControllerFilter - filter down all controllers to just API controllers
  • IApiControllerSpecification - identify an API controller

There are two built-in specifications one for detecting API controllers by looking for whether the ApiControllerAttribute has been applied (aka API Behaviors). This can be applied at the controller or assembly level. The second is looking for OData controllers (if you're usng it). The default filter accepts all specifications and removes any that are not satisfied. The old UseApiBehavior = false was a shortcut to not using any filtering.

If you truly need custom filtering, you can replace any of the services and/or provide custom filters or specifications. If all you want is the equivalence of UseApiBehavior = false, then an empty filter is provided out-of-the-box that you can use to replace the default service like this:

builder.Services.AddTransient<IApiControllerFilter, NoControllerFilter>();
builder.Services.AddApiVersioning();

I will make it a point to add some additional information about this in the migration guide.

A similar question was asked on SO:
https://stackoverflow.com/questions/76602962/what-does-useapibehavior-property-do-in-the-apiversioning-library

from aspnet-api-versioning.

GeorgeNarcis avatar GeorgeNarcis commented on July 20, 2024 1

Hi thanks for the detailed explanation. As it seems we don t need it anymore and was legacy from the beginning of the project

from aspnet-api-versioning.

commonsensesoftware avatar commonsensesoftware commented on July 20, 2024

I've added a section about API Behaviors in the migration guide. Hopefully, that help clear things up and helps other people migrating.

from aspnet-api-versioning.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.