Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 1.94 KB

AdvancedReadme.md

File metadata and controls

61 lines (44 loc) · 1.94 KB

AtomicAssetsClient: Advanced scenarios

Configure HttpClient

AtomicClient requests named instance from HttpClientFactory, so configure that named instance:

services.AddHttpClient(new AtomicClientOptions().HttpClientName).ConfigureHttpClient(...)

Use with EOS network

WAX network is used by default. To switch to EOS network change AtomicClientOptions.Endpoint:

services.Configure<AtomicClientOptions>(o => o.Endpoint = new Uri("https://eos.api.atomicassets.io"));

Use WAX and EOS simultaneously in same app

You need two different instances of AtomicClient, initialized with different Endpoint values in AtomicOptions.

If you use advanced DI libraries which supports multiple registrations - use it, I guess you don't need help.

If you use default .NET DI, you may need additional classes:

public interface IWaxAtomicClient : IAtomicClient { /* Nothing inside */ }

public interface IEosAtomicClient : IAtomicClient { /* Nothing inside */ }
    
public class WaxAtomicClient : AtomicClient, IWaxAtomicClient
{
    public WaxAtomicClient(ILogger<AtomicClient> logger, IOptions<AtomicClientOptions> options, HttpClientFactory httpClientFactory)
        : base(logger, options, httpClientFactory)
    {
        // Nothing inside
    }
}

public class EosAtomicClient : AtomicClient, IEosAtomicClient
{
    public EosAtomicClient(ILogger<AtomicClient> logger, IOptions<AtomicClientOptions> options, HttpClientFactory httpClientFactory) 
        : base(logger, options, httpClientFactory)
    {
        options.Value.Endpoint = new Uri("https://eos.api.atomicassets.io");
    }
}

Then register them both:

services.AddHttpClient();
services.Configure<AtomicClientOptions>(Configuration.GetSection("AtomicClientOptions"));
services.AddSingleton<IWaxAtomicClient, WaxAtomicClient>();
services.AddSingleton<IEosAtomicClient, EosAtomicClient>();

And consume IWaxAtomicClient or IEosAtomicClient as needed.