Skip to content

Latest commit

 

History

History
62 lines (56 loc) · 1.44 KB

README.md

File metadata and controls

62 lines (56 loc) · 1.44 KB

Sharkable

a dotnet minimal api framework collection

Sharkable Sharkable

Usage

automatic dependency injection

//first add extension
using Sharkable
builder.Services.AddShark();
//for aot users please specify assemblies by youself and avoid code trim
build.Services.AddShark([typeof(Program).Assembly]);

[ScopedService] //inject class as a scoped service by the given attribute
public class Monitor : IMonitor
{
    public void Show()
    {
        ...
    }
}

//map an endpoint and it works!
app.MapGet("/monitor",([FromServices]IMonitor monitor) =>
{
    monitor.Show();
});

endpoint auto mapper (new style)

create a new class

public class TestEndpoint : ISharkEndpoint
{
    public void AddRoutes(IEndpointRouteBuilder app)
    {
        app.MapGet("show", ()=>"test result");
    }
}

//will now generate a http get method with the url
// api/test/show

endpoint auto mapper (old style)

create a new class

[SharkEndpoint]
public class TestEndpoint
{
    [SharkMethod("show", SharkHttpMethod.GET)]
    public void Show()
    {
        ...
    }
}

//will now generate a http get method with the url
// api/test/show

for more use sample please see Sharkable.Sample project