Provider extensions

'Provider Extensions' is an extra layer on top of the core SDK, it bundles a set of useful backend interactions that could definitely save you some time and effort. In addition to Venly's services, these functions also interact with your backend services (such as an identity system or inventory system).

The available provider extension functions are listed below. There is a default behavior for each of these functions, but you can always choose to override that behavior if necessary.

FunctionDescription
GetServerInfoReturns backend information (VenlyCore Api Version, Venly Environment)
InvokeMakes it easy to call custom functions declared in your Cloudscript/Microservice
HasWalletChecks whether a wallet has been linked to the logged-in User
CreateWalletForUserCreates, links (Backend Identity Service), and returns a new wallet for a (new) logged-in User (If none is linked already)
GetWalletForUserRetrieves the wallet for an (existing) logged-in User

And because it is built on top of our C#/.NET SDK SDK, all functions of Venly's exposed API products are also available for usage in your server-side logic.​

Developer mode

🚧

The Default implementation will throw a 'NotSupported' exception when calling one of the extension functions while using Developer Mode.

You have the flexibility to supply an alternative implementation for these extensions within the SDK. Refer to the Overriding Provider Extensions section for detailed information.

Beamable

These extensions will automatically streamline essential interactions with Beamable's services from inside your Beamable Microservice. Tasks such as retrieving a walletId from the active user or linking a walletId to an active user are handled automatically. This Default Behavior offers a built-in, straightforward, and user-friendly approach for executing common interactions with the Beamable Backend.

📘

The Provider extensions for Beamable are already part of the Venly Unity SDK, there is no need to install an extra package.

📘

For Beamable, the Default Extension Behaviour stores the data, such as walletId/subUserId, as a private Stat of the corresponding user. Feel free to override this Default Behaviour by Overriding the Provider Extensions for Beamable.

PlayFab

The PlayFab-Azure Provider Extension is built on top of the C#/.NET SDK and provides a frictionless implementation to use PlayFab (Azure CloudFunctions) with the Venly Unity SDK. Required backend interaction such as retrieving a walletId from the logged-in user, or linking a walletId to a new user for example are automatically performed.

The library is available as a NuGet package, which can be downloaded here.

📘

For PlayFab, the Default Extension Behaviour stores the data (like 'walletId') inside the Internal Player Data of the corresponding user. Feel free to override this Default Behaviour by Overriding the Provider Extensions for PlayFab.

Custom Backend

You can easily define your own Extension Behaviour for any Custom Provider.

📘

The Default Extension Behaviour will be used in case a custom implementation is not provided. (Resulting in 'Not Supported' exceptions on invocation)

In case you have a Custom Backend Extension for your Custom Backend Provider, make sure to register the implementation during the Initialization (See Custom Backend Provider for more details on configuring your own Backend Provider).

//Inside your Custom Provider (BackendProvider) class
protected override void OnInitialize()
{
    //Your Custom Backend Provider Intialization Logic
    //...
    OverrideExtension(...); //Here your can set your custom extension implementation
}

Overriding

Overriding the Provider Extensions behavior is pretty easy, in order to override the extensions you need to:

  • Create a custom implementation for the Extensions (using the IBackendExtensions interface)
  • Tell the SDK to use your custom implementation

Create a Custom Implementation

public class CustomBackendExtension : IBackendExtension
{
    public VyTask<VyWalletDto> CreateWalletForUser(VyCreateWalletDto reqParams, object customData = null)
    {
        //Here you can add your own behaviour to Create a wallet for a new 'user'
        //The 'user' is of course defined by the Identity Service of the Backend Provider you are using
        //...
    }

    public VyTask<VyWalletDto> GetWalletForUser(object customData = null)
    {
        //Here you can add your own behaviour to Retrieve a wallet for an existing 'user'
        //The 'user' is of course defined by the Identity Service of the Backend Provider you are using
        //...
    }
}

Register a Custom Implementation

There are multiple ways to register your own Provider Extensions, here are a few examples.

//During Initialization
Venly.Initialize(new CustomBackendExtensions())
//Or Overriding an existing implementation after Initialization
Venly.OverrideBackendExtensions(new CustomBackendExtension(), eVyBackendProvider.DevMode);
//Or during the Initialization of a Custom Backend Provider (See Custom Provider Page)
//Following function override would be inside a Custom Backend Provider class
protected override void OnInitialize()
{
    //Your Custom Backend Provider Intialization Logic
    //...
    OverrideExtension(new CustomBackendExtension());
}

Reset back Default Behaviour

//In order to reset the extensions back to the Default Behaviour, pass 'null'
//Default Behavior throws 'NotSupported' exceptions on invocation
Venly.OverrideBackendExtensions(null, eVyBackendProvider.DevMode);
OverrideExtension(null);