This presentation is about how to build mobile apps that are connected to the network. I talk about how you can't rely on infinite and uninterrupted bandwidth and how you can leverage existing components from Nuget to make your app more resilient.
is zero. 3. Bandwidth is infinite. 4. The network is secure. 5. Topology doesn't change. 6. There is one administrator. 7. Transport cost is zero. 8. The network is homogeneous. Deutsch - 1994 Gosling - 1997 distributed computing
MyMethod(int parameter) { } MyMethod(10).Run(); This will execute the task on the same thread, blocking the UI thread var result = await MyMethod(10); // async all the way! Pitfall
Task DoLotsOfNetworkCalls() { await httpClient.GetAsync(“…”); // do some calculations or de-serialization await httpClient.GetAsync(“…”); } After each await, execution will continue on the original thread, causing interruptions and even possibly deadlocks. await httpClient.GetAsync(“…”).ConfigureAwait(false); // use ConfigureAwait(false) in your library code Pitfall
Awaiting this method will fail This is a Fire & Forget call, you cannot do any proper error handling async Task<bool> MyMethod(int parameter) { } async void OnClick(object sender, EventArgs e) { } // Exception: async event handlers! Pitfall
RESTful API into a typesafe interface public interface IGitHubApi { [Get("/users/{user}")] Task<User> GetUser(string user); } Component by: Paul Betts, http://github.com/paulcbetts/Refit
file is stored. – The location must be writable! • If you bundle a database file in your app, copy it out first! • Different platforms “care” about different things • Android: choose internal or external storage • iOS: choose Documents, Library or other
by swapping in a NativeMessageHandler: • NSURLSession on iOS • OkHttp on Android Beware: exceptions are not the same as with plain HttpClient (e.g. Java web exceptions) Beware: iOS App Transport Security (use TLS2.0 edit info.plist) Component by: Paul Betts, http://github.com/paulcbetts/ModernHttpClient Faster network requests
to check the connectivity of the device before trying to issue a network request. Component by: James Montemagno, https://github.com/jamesmontemagno/Xamarin.Plugins Work Offline
specifying retry, circuit breaker etc. Polly will do the heavy lifting. Polly by: Michael Wolfenden, https://github.com/michael-wolfenden/ Handle errors