Thanks for the link Pang
When using AddScoped, it's by design...
There is an example just below in the documentation: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-8.0#disposal-of-services
A brief excerpt from this example:
public class Service1 : IDisposable
...
builder.Services.AddScoped<Service1>();
...
public class IndexModel : PageModel
{
private readonly Service1 _service1;
public IndexModel(Service1 service1)
{
_service1 = service1;
}
public void OnGet()
{
_service1.Write("IndexModel.OnGet");
}
}
...
Console:
Service1: IndexModel.OnGet
Service1.Dispose