public static class AssetSyncServiceClientFactory
{
private static readonly Lazy<IAssetSyncServiceClient> _instance = new Lazy<IAssetSyncServiceClient>(() => new AssetSyncServiceClient());
/// <summary>
/// Gets the AssetSync service client singleton; creates lazily if necessary.
/// </summary>
/// <returns>The AssetSync service client singleton.</returns>
public static IAssetSyncServiceClient GetAssetSyncServiceClient()
{
return _instance.Value;
I made the Exception specifically so that a different implementation of AssetSyncServiceClient could use it
because its errorType is an int instead of an enum so another implementation could add new values with its own enum
i've always thought Exception should have a better way of passing specific error codes back to calling code; i've often seen calling code parsing the Message string which is crazy
what if the error message changes a bit or changes language?
so i tend to put in custom error code functionality
#region Private vars
private const string _defaultMsg = "There was a miscellaneous error with the AssetSync service client.";
private const int _assetSyncServiceClientErrorTypeOther = 0;
#endregion
private HttpClient _client {
get {
lock (_lock) {
if (!_initialized) { throw new AssetSyncServiceClientException("HTTP client has not been initialized."); }
return _instanceClient;
}
}
}
(that's actually another annoyance; Microsoft don't like you throwing exceptions inside getters which i think is stupid. weirdly when i changed the exception i threw to my own exception, it stopped giving me a code style warning)
but MS say that properties are "smart fields" and shouldn't throw because the sort of "look like fields". bullshit. they look like properties and they are methods.
so according to MS i should technically Java-ize the code and have a GetInstance method
i so desperately wish MS had just standardized on \n when they released windows NT
also, why the hell are they still defaulting to \r\n? literally the only text editor that can't deal with \n is notepad and that isn't even installed in win10
also, what do you think about having PingServiceAsync in the same class as the HttpClient?
i'm thinking it's ok but i bet some would separate that (and all the other methods for various web api calls) into another class that calls the HttpClient wrapper
It seems to me that these days, good OOP design is basically predicated on inversion of control. Pretty much the first question you should be asking for any design pattern is "is the control inverted?"
The thing should implement an interface, it should be instantiated elsewhere, it should have ...