September 24, 2020

Build 2015 Summary: API Contracts

This is another Build 2015 session recording, the topic is API Contracts. API Contract is a new concept in Universal Windows Platform. If you develop for Windows 10, this is something you have know. Basically They put some functionally related APIs inside a group, APIs in this group are either fully implemented nor not at all. So to use them you only need to check the API Contract instead of each one. Also talked about is Adaptive Programming in UWP using run time detection. Actually the video embedded below is not a video, it is a number of slides. You have to click the error button to move from slides to slides. I put the summary after the slides.


>>There are three aspects of adaptive programming in UWP:

> OS Version Adaptive
App runs on a base OS version but can use up-level APIs

> Device Family Adaptive
App uses device family specific APIs

> Form factor adaptive
App UI adjusts itself to different form factors

>>Version Adaptive:
>Windows is shipping more frequently, you can always call new APIs when they are availble in new version, but still work with base version.

>Target older version OS for most market share, support new OS for cutting edge features.

>>Device Family Adaptive
The more device family you support, the bigger market you can reach.

>> In Windows 10, >85% APIs are common

>> API detection has different levels:
1. if the API exists, if not, it throws exceptions
2. the API exists, but does nothing
3. API exists, does partial functionalities
4. API exists, supports full functionalities
5. API exists, supports full functionalities, with different behavior
6. API exists, supports full functionalities, added new functionalities not supported before

>> There is a full set of functions to detect present of APIs:

static class ApiInformation {
Boolean IsTypePresent([in] HSTRING typeName);


>> What is an API Contract?
A named and versioned set of functionally related APIs. API means types, interfaces, properties, methods, events, structs, enums
API contracts are atomic: Either API must be implemented of none of them.

>> Every WinRT API resides in an API contract.

>>APIs being in API Contract guarantees
Implemented in its entirety or not at all.
Support can be queried at runtime
Backward comparable

>>Adaptive Coding examples (hypothetical):

if(ApiInformation.IsTypePresent(“Windows.Networking.HttpClients”) {
HttpClient2 cleint = new Windows.Networking.HttpClient2();

if(ApiInformation.IsApiContractPresent(“Windows.Networking.networkingGameBroadcastContract”, 2, 0)) {
GameBroadcast gb = new GameBroadcast();
GameParty gp= new GameParty();

>> The concept of Device Family

Device family: like phone, XBox, implement API contracts that are not implemented in UWP.
Device family APIs are implemented in Extension SDKs, project need to reference those Extension SDKs to code the device family.