Avoid referencing virtual members in constructor.

Since the call to GetRootPathFromUrl may be expensive, we cache the
value using a lazy initializer.
This commit is contained in:
Kenneth Hsu
2018-09-30 15:06:49 -07:00
parent 7cf830cad7
commit f9022fec66
@@ -74,13 +74,15 @@ namespace Duplicati.Library.Backend
private readonly JsonSerializer m_serializer = new JsonSerializer();
private readonly OAuthHttpClient m_client;
private readonly string m_path;
private readonly int fragmentSize;
private readonly int fragmentRetryCount;
private readonly int fragmentRetryDelay; // In milliseconds
private string[] dnsNames = null;
private Lazy<string> rootPathFromURL;
private string m_path => this.rootPathFromURL.Value;
protected MicrosoftGraphBackend() { } // Constructor needed for dynamic loading to find it
protected MicrosoftGraphBackend(string url, string protocolKey, Dictionary<string, string> options)
@@ -121,7 +123,7 @@ namespace Duplicati.Library.Backend
this.m_client.BaseAddress = new System.Uri(BASE_ADDRESS);
// Extract out the path to the backup root folder from the given URI
this.m_path = NormalizeSlashes(this.GetRootPathFromUrl(url));
this.rootPathFromURL = new Lazy<string>(() => this.GetRootPathFromUrl(url));
}
public abstract string ProtocolKey { get; }