Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmsfernandes/endpointdefinitions
A library to enable the easy definition of endpoints with .NET6 minimal API projects.
https://github.com/jmsfernandes/endpointdefinitions
csharp dotnet minimal-apis nuget
Last synced: 29 days ago
JSON representation
A library to enable the easy definition of endpoints with .NET6 minimal API projects.
- Host: GitHub
- URL: https://github.com/jmsfernandes/endpointdefinitions
- Owner: jmSfernandes
- Created: 2022-06-29T08:54:11.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-16T14:45:43.000Z (about 1 year ago)
- Last Synced: 2024-04-27T00:41:59.321Z (8 months ago)
- Topics: csharp, dotnet, minimal-apis, nuget
- Language: C#
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EndPointDefinitions
[![Nuget badge](https://img.shields.io/nuget/v/MinimalApi.EndPointDefinitions)](https://www.nuget.org/packages/MinimalApi.EndPointDefinitions/1.0.0)
[![Nuget badge](https://img.shields.io/nuget/dt/MinimalApi.EndPointDefinitions)](https://www.nuget.org/packages/MinimalApi.EndPointDefinitions/1.0.0)A library to enable the easy definition of endpoints with .NET8 minimal API projects.
To use import the project from [nuget](https://www.nuget.org/packages/MinimalApi.EndPointDefinitions/1.0.0).
A full example of how to use the library is available in this [project](https://github.com/jmSfernandes/ExampleEndpointDefinitions).
## Using the library:
Defining an Endpoint:
```C#public class WeatherEndpoint : IEndpointDefinition
{
public void DefineServices(IServiceCollection services)
{
//Define services here
services.AddScoped();
}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](https://github.com/jmSfernandes/ExampleEndpointDefinitions) 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:
```C#
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 LicenseCopyright (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.