MinimalApi.EndPointDefinitions 1.0.2

dotnet add package MinimalApi.EndPointDefinitions --version 1.0.2                
NuGet\Install-Package MinimalApi.EndPointDefinitions -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MinimalApi.EndPointDefinitions" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MinimalApi.EndPointDefinitions --version 1.0.2                
#r "nuget: MinimalApi.EndPointDefinitions, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MinimalApi.EndPointDefinitions as a Cake Addin
#addin nuget:?package=MinimalApi.EndPointDefinitions&version=1.0.2

// Install MinimalApi.EndPointDefinitions as a Cake Tool
#tool nuget:?package=MinimalApi.EndPointDefinitions&version=1.0.2                

EndPointDefinitions

Nuget badge Nuget badge

A library to enable the easy definition of endpoints with .NET8 minimal API projects.

To use import the project from nuget.

A full example of how to use the library is available in this project.

Using the library:

Defining an Endpoint:


public class WeatherEndpoint : IEndpointDefinition
{
    public void DefineServices(IServiceCollection services)
    {
        //Define services here
        services.AddScoped<IWeatherService, WeatherService>();
    }

    public void DefineEndpoints(WebApplication app)
    {
        app.MapGet("/weatherforecast", GetWeatherForecast)
            .WithName("GetWeatherForecast");
    }
...

}

To define an Endpoint you need to implement the IEndpointDefinition interface, and override both of the methods showed.

You do not need to use Services, you can define the GetWeatherForecast as a lambda or a extracted method within the Endpoint Class.

The example serves only to show that it is possible to use services and dependency injection with the library.

And you have full control to still define your services lifecycle.

You can check the full example project to see the full implementation.

Then you only need to call the Services.AddAllEndpointDefinitions or the Services.AddEndpointDefinition(Type type) to define the endpoints.

And the app.UseEndpointDefinitions() to start the Endpoints.

As shown here:


builder.Services.AddAllEndpointDefinitions();

//its also possible to filter for specific endpointDefinitions
//builder.Services.AddEndpointDefinitions(typeof(WeatherEndpoint));
...

var app = builder.Build();

...

//Start Endpoint definitions
app.UseEndpointDefinitions();
app.Run();

LICENSE

MIT License

Copyright (c) 2022 J. Fernandes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 277 11/16/2023
1.0.0 272 6/29/2022