Sharing Default MVC controller

Viewed 196

At the moment I am building a lot of small API's at work. Many of these projects shares some basic controllers logic. Is there some way to add them to a nuget package and just use them during startup?
Eg. like adding Mvc:

IApplicationBuilder app;    
....    

app.UseMvc;
app.UseBasicApiVersionController();

The idea is we have version endpoint in all our microservices.
Eg:
http://url/version
returns { "version": "1.0.0" }
How would I make this into a nuget package?
So all developers only have to add 1 line of code to add this endpoint to their micro service? We are using dotnet core.
Don't help to create the nuget package it self :)

My guess for getting started is something similar to this:

public static IApplicationBuilder UseBasicApiVersionController(this IApplicationBuilder app)
    {
      if (app == null)
        throw new ArgumentNullException("app");

      ..... // What should I do?

      return app;
    }

*Edit:
If you add a controller to nuget package project it will be automatic detected. But that is not the functionality I want.
I might have 10 services that need that controller. While having 1-2 services that only want's the other version control logic. Eg. Customer facing App's shouldn't have a "/version" endpoint.
That's why I want during startup to use app.UseBasicApiVersionController();

1 Answers
Related