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

Prevent DI Configuration HttpClient from being overwritten on init #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GuidoNeele
Copy link

This change makes sure the Configuration is used that is supplied during DI.

At the moment the Configuration.HttpClient is being overwritten because ImageServiceBase.InitializeIfNeeded will always at least run once. The line below will always override the implementation done via DI since userDefinedConfig will always be null when it's initialized the first time.

var httpClient = userDefinedConfig.HttpClient ?? new HttpClient(new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.All });

var ffilConfig = new FFImageLoading.Config.Configuration()
{
AllowUpscale = true,
DiskCacheDuration = TimeSpan.FromDays(AppData.CACHE_DURATION),
DiskCachePath = CreateDiskCachePath(),
HttpClient = new HttpClient(new AuthenticatedHttpImageClientHandler(SessionManagerStatic.GetAccessTokenAsync)),
HttpHeadersTimeout = HttpSettings.HttpHeadersTimeoutForImages,
HttpReadTimeout = HttpSettings.HttpReadTimeoutForImages
};
builder.Services.AddSingleton<FFImageLoading.Config.IConfiguration>(ffilConfig);

This should be the preferred way to configure FFImageLoading but at the moment it doesn't work because of the above issue.

@GuidoNeele
Copy link
Author

Is this in consideration?

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

Successfully merging this pull request may close these issues.

1 participant