Skip to content

Commit

Permalink
Update Architecture.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno authored Sep 1, 2017
1 parent a7ccd5b commit a763bab
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion docs/Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,62 @@ public MyViewModel()
### What About Unit Testing?
To learn about unit testing strategies be sure to read my blog: [Unit Testing Plugins for Xamarin](http://motzcod.es/post/159267241302/unit-testing-plugins-for-xamarin)

## Disposing of In-App Billing Plugin
This plugin also implements IDisposable on all implementations. This ensure that all events are unregistered from the platform. This include unregistering from the SKPaymentQueue on iOS. Only dispose when you need to and are no longer listening to events and you must call `Dispose` on the actual static class. The next time you gain access to the `CrossInAppBilling.Current` a new instance will be created.

<= Back to [Table of Contents](README.md)
```csharp
public async Task<bool> MakePurchase()
{
if(!CrossInAppBilling.IsSupported)
return false;

using(var billing = CrossInAppBilling.Current)
{
try
{
var connected = await billing.ConnectAsync();
if(!connected)
return false;

//make additional billing calls
}
finally
{
await billing.DisconnectAsync();
}
}
CrossInAppBilling.Dispose();
}
```

It is recommended to not us a using statement, but instead just call the single `Dispose` on the static class, which will also dispose the `Current`:

```csharp
public async Task<bool> MakePurchase()
{
if(!CrossInAppBilling.IsSupported)
return false;

var billing = CrossInAppBilling.Current;

try
{
var connected = await billing.ConnectAsync();
if(!connected)
return false;

//make additional billing calls
}
finally
{
await billing.DisconnectAsync();
}
//This does all the disposing you need
CrossInAppBilling.Dispose();
}
```


<= Back to [Table of Contents](README.md)

0 comments on commit a763bab

Please sign in to comment.