Skip to content

Instantly share code, notes, and snippets.

@jamie94bc
Created March 23, 2014 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamie94bc/9721818 to your computer and use it in GitHub Desktop.
Save jamie94bc/9721818 to your computer and use it in GitHub Desktop.
A more "MvvmCross" implementation of https://github.com/paulcbetts/ModernHttpClient.
public class App : Cirrious.MvvmCross.ViewModels.MvxApplication {
public override void Initialize() {
Mvx.LazyConstructAndRegisterSingleton<IHttpClientFactory, DefaultHttpClientFactory>();
RegisterAppStart(new AppStart());
}
}
public class DefaultHttpClientFactory : IHttpClientFactory {
public HttpClient Get() {
var handler = new HttpClientHandler();
if (handler.SupportsAutomaticDecompression) {
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
return new HttpClient(handler);
}
}
public class DroidHttpClientFactory : IHttpClientFactory {
public HttpClient Get() {
return new HttpClient(new OkHttpNetworkHandler());
}
}
public class Setup : MvxAndroidSetup {
protected override void InitializeLastChance() {
base.InitializeLastChance();
Mvx.LazyConstructAndRegisterSingleton<IHttpClientFactory, DroidHttpClientFactory>();
}
}
public interface IHttpClientFactory {
HttpClient Get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment