DI on Endpoints
nestenius opened this issue · comments
How do I make Endpoints work with DI as in following code:
public class Accounts : EndpointGroupBase
{
private readonly ITokenService _identityService;
public Accounts(
ITokenService identityService)
{
_identityService = identityService;
}
public override void Map(WebApplication app)
{
app.MapGroup(this)
.MapPost(Login);
}
public async Task Login(ISender sender, TokenRequest model)
{
var response = await _identityService.LoginAsync(model);
return await sender.Send(command);
}
}
As far as I am aware, this is not supported. The idea is that each endpoint can define its own dependencies. If you want to dig deeper, the main concepts used in this template include:
I'd recommend you just inject identity service wherever it is required.