Skip to content

Instantly share code, notes, and snippets.

@PoisonousJohn
Last active February 20, 2018 17:18
Show Gist options
  • Save PoisonousJohn/96ea14616e32cd99b2686237525f8b6c to your computer and use it in GitHub Desktop.
Save PoisonousJohn/96ea14616e32cd99b2686237525f8b6c to your computer and use it in GitHub Desktop.
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