Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.02 KB

File metadata and controls

53 lines (40 loc) · 1.02 KB

| EN

MinimalAPI

Original usage:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/api/v1/helloworld", ()=>"Hello World");
app.Run();

Example:

Install-Package MASA.Contrib.Service.MinimalAPIs
  1. Add MinimalAPI
var builder = WebApplication.CreateBuilder(args);
var app = builder.Services
                 .AddServices(builder);
  1. Customize Service and inherit ServiceBase
public class IntegrationEventService : ServiceBase
{
    public IntegrationEventService(IServiceCollection services) : base(services)
    {
        App.MapGet("/api/v1/payment/HelloWorld", HelloWorld);
    }

    public string HelloWorld()
    {
        return "Hello World";
    }
}

Tip: The service that inherits ServiceBase is registered in singleton mode, if you need to obtain it from DI

public async Task DeleteBasketByIdAsync(string id, [FromServices] IBasketRepository repository)
{
    await repository.DeleteBasketAsync(id);
}