GithubHelp home page GithubHelp logo

Comments (2)

Sebazzz avatar Sebazzz commented on June 18, 2024

If you're using attribute routing I suggest you inherit both controllers from a base class, and putting a routeprefix in the version implementation. Otherwise, check out the newer beta version.

from sdammann.webapi.versioning.

KenBrannigan avatar KenBrannigan commented on June 18, 2024

@Sebazzz I upgraded to the 3.0 beta as you stated.

Here is my configuration code which uses Autofac for by dependency injector:

`// Create our autofac dependency container.
ContainerBuilder builder = new ContainerBuilder();

        // Add controller to our dependency container.
        builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

        // Add items to our dependency container needed for our api versioning.
        builder.Register(c => new DefaultControllerIdentificationDetector(config));
        builder.Register(c => new DefaultRequestControllerIdentificationDetector(config));
        
        // Build our dependency container and set as our dependency resolver.
        IContainer container = builder.Build();
        config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        
        // Setup our routes.
        config.MapHttpAttributeRoutes();

        // Set our url based api versioning.
        ApiVersioning.Configure(config)
            .ConfigureRequestVersionDetector<DefaultRouteKeyVersionDetector>();`

Again my controller configuration is as follows:

Controllers
-Version1
--AccountController.cs
-Version2
--AccountController.cs (Inherits from Version1 controller)

An example of a route attribute I placed on the version 1 controller:

[Route("v{version}/account/login")]

When I request this route using Postman I get a 404 error.

Can you confirm this setup should be supported using the beta version and if so what configuration changes do you recommend to pull it off?

Also what lifetime scope should be applied to the two items added to the dependency injector:

DefaultControllerIdentificationDetector
DefaultRequestControllerIdentificationDetector

Thank you in advance for any help you can provide.

Take care,
Ken

from sdammann.webapi.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.