Skip to content

Get rid of IHealthChecksBuilder.AddTypeActivatedCheck<T> in Microsoft.Extensions.DependencyInjection.HealthChecksBuilderAddCheckExtensions #41380

Open
@RyanLiu99

Description

@RyanLiu99

Background and motivation

AddTypeActivatedCheck support additional arguments to concert type constructor which implements IHealthCheck.
This sounds good idea, but it brought few issues.

First, I feel it is not really needed.

More important, it might cause memory leak.

It resolves (some) HealthCheck constructor arguments from IoC container, and not resolve HealthCheck itself from Ioc container ( to support additional constructor arguments). This bring few issues:

The runtime create particular HealthCheck instance each time Health end point is hit. Since itself is not managed by Ioc container, lifetime does not apply to it. Ioc container cannot dispose it even it is a IDisposable. Heath check Runtime just create it but does not dispose it either. Application cannot dispose it since it was not created by application itself.

So it was created each time when health check is performed and never disposed. That can cause resource/memory leak.
I call it "Memory leak introduced by Ioc container leak" -- HealthCheck instances are not managed by Ioc container, but their dependencies are. Those dependencies are referred by HealthCheck but their lifetime can out of sync, this can cause another type issue.

API Proposal

//Get rid of AddTypeActivatedCheck method.



### API Usage

Get rid of extension method  AddTypeActivatedCheck<T> of IHealthChecksBuilder.


### Alternative Designs

_No response_

### Risks

Existing code depends on it need rewritten.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-healthchecksIncludes: Healthchecks (some bugs also in Extensions repo)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions