-
Notifications
You must be signed in to change notification settings - Fork 253
Open
Description
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?
aRRma
Metadata
Metadata
Assignees
Labels
No labels