Skip to content

Commit

Permalink
Better fix for #223
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-luberda committed Jun 3, 2016
1 parent 7d56358 commit 9ef44c0
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions source/FFImageLoading.Shared/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,55 @@ public class ImageService: IImageService
public static IImageService Instance { get { return LazyInstance.Value; } }

private ImageService() { }

/// <summary>
/// Gets FFImageLoading configuration
/// </summary>
/// <value>The configuration used by FFImageLoading.</value>
public Configuration Config { get; private set; }

/// <summary>
/// Initializes FFImageLoading with given Configuration. It allows to configure and override most of it.
/// </summary>
/// <param name="configuration">Configuration.</param>
public void Initialize(Configuration configuration)
public Configuration Config
{
get
{
InitializeIfNeeded();
return _config;
}

set
{
_config = value;
}
}

/// <summary>
/// Initializes FFImageLoading with given Configuration. It allows to configure and override most of it.
/// </summary>
/// <param name="configuration">Configuration.</param>
public void Initialize(Configuration configuration)
{
lock (_initializeLock)
{
_initialized = false;

if (Config != null)
if (_config != null)
{
// If DownloadCache is not updated but HttpClient is then we inform DownloadCache
if (configuration.HttpClient != null && configuration.DownloadCache == null)
{
configuration.DownloadCache = Config.DownloadCache;
configuration.DownloadCache = _config.DownloadCache;
configuration.DownloadCache.DownloadHttpClient = configuration.HttpClient;
}

// Redefine these if they were provided only
configuration.HttpClient = configuration.HttpClient ?? Config.HttpClient;
configuration.Scheduler = configuration.Scheduler ?? Config.Scheduler;
configuration.Logger = configuration.Logger ?? Config.Logger;
configuration.DownloadCache = configuration.DownloadCache ?? Config.DownloadCache;
configuration.HttpClient = configuration.HttpClient ?? _config.HttpClient;
configuration.Scheduler = configuration.Scheduler ?? _config.Scheduler;
configuration.Logger = configuration.Logger ?? _config.Logger;
configuration.DownloadCache = configuration.DownloadCache ?? _config.DownloadCache;

// Skip configuration for maxMemoryCacheSize and diskCache. They cannot be redefined.
if (configuration.Logger != null)
configuration.Logger.Debug("Skip configuration for maxMemoryCacheSize and diskCache. They cannot be redefined.");
configuration.MaxMemoryCacheSize = Config.MaxMemoryCacheSize;
configuration.DiskCache = Config.DiskCache;
configuration.MaxMemoryCacheSize = _config.MaxMemoryCacheSize;
configuration.DiskCache = _config.DiskCache;
}


Expand Down

0 comments on commit 9ef44c0

Please sign in to comment.