Last active
February 20, 2018 17:18
-
-
Save PoisonousJohn/96ea14616e32cd99b2686237525f8b6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class Services | |
{ | |
public static IAPIService api { get { return _api.Value; } } | |
public static bool isOffline { get; set; } | |
private static Lazy<IAPIService> _api = new Lazy<IAPIService>(() => isOffline | |
? (IAPIService)new OfflineAPIService() | |
: new APIService()); | |
} | |
public interface IAPIService | |
{ | |
string UserId { get; } | |
void Login(); | |
} | |
public class APIService : IAPIService | |
{ | |
public string UserId | |
{ | |
get | |
{ | |
return _userId; | |
} | |
} | |
public void Login() | |
{ | |
// send request to server | |
} | |
private string _userId; | |
} | |
public class OfflineAPIService : IAPIService | |
{ | |
public string UserId | |
{ | |
get | |
{ | |
return "offlineUser"; | |
} | |
} | |
public void Login() | |
{ | |
// do nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment