79121392

Date: 2024-10-24 10:06:51
Score: 1.5
Natty:
Report link

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    
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: VictorNS