Created
March 23, 2014 11:19
-
-
Save jamie94bc/9721818 to your computer and use it in GitHub Desktop.
A more "MvvmCross" implementation of https://github.com/paulcbetts/ModernHttpClient.
This file contains 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
public class App : Cirrious.MvvmCross.ViewModels.MvxApplication { | |
public override void Initialize() { | |
Mvx.LazyConstructAndRegisterSingleton<IHttpClientFactory, DefaultHttpClientFactory>(); | |
RegisterAppStart(new AppStart()); | |
} | |
} |
This file contains 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
public class DefaultHttpClientFactory : IHttpClientFactory { | |
public HttpClient Get() { | |
var handler = new HttpClientHandler(); | |
if (handler.SupportsAutomaticDecompression) { | |
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; | |
} | |
return new HttpClient(handler); | |
} | |
} |
This file contains 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
public class DroidHttpClientFactory : IHttpClientFactory { | |
public HttpClient Get() { | |
return new HttpClient(new OkHttpNetworkHandler()); | |
} | |
} |
This file contains 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
public class Setup : MvxAndroidSetup { | |
protected override void InitializeLastChance() { | |
base.InitializeLastChance(); | |
Mvx.LazyConstructAndRegisterSingleton<IHttpClientFactory, DroidHttpClientFactory>(); | |
} | |
} |
This file contains 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
public interface IHttpClientFactory { | |
HttpClient Get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment