Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinioClient Injection Logic with ServiceLifetime Can Be Confusing #1268

Open
gxrsprite opened this issue Feb 19, 2025 · 0 comments
Open

MinioClient Injection Logic with ServiceLifetime Can Be Confusing #1268

gxrsprite opened this issue Feb 19, 2025 · 0 comments

Comments

@gxrsprite
Copy link

I’ve been reviewing the code for dependency injection of MinioClient in the minio-dotnet SDK, and I noticed some potential confusion in the way the client is being injected based on the ServiceLifetime provided.

In the code:
https://github.com/minio/minio-dotnet/blob/master/Minio/ServiceCollectionExtensions.cs

var client = minioClientFactory.CreateClient();
client.Config.ServiceProvider = services.BuildServiceProvider();
switch (lifetime)
{
    case ServiceLifetime.Singleton:
	services.TryAddSingleton(_ => client);
	break;
    case ServiceLifetime.Scoped:
	services.TryAddScoped(_ => client);
	break;
    case ServiceLifetime.Transient:
	services.TryAddTransient(_ => client);
	break;
}

The issue is that the client is being created first and then injected as a singleton, scoped, or transient instance based on the lifetime provided. However, it seems like the code is always injecting the same instance of MinioClient, which makes the ServiceLifetime setting effectively irrelevant.

whether it's recommended to use MinioClient as a Singleton or as a Transient/Scoped instance in a typical application?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant