43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using IronServices.Client;
|
|
using IronServices.Maui.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace IronServices.Maui;
|
|
|
|
/// <summary>
|
|
/// Extension methods for registering IronServices with MAUI dependency injection.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds IronServicesClient with secure token storage for MAUI apps using default URLs.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddIronServices(this IServiceCollection services)
|
|
{
|
|
return services.AddIronServices(_ => { });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds IronServicesClient with secure token storage and custom configuration.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configure">Configuration action for the client options.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddIronServices(this IServiceCollection services, Action<IronServicesClientOptions> configure)
|
|
{
|
|
var options = new IronServicesClientOptions();
|
|
configure(options);
|
|
|
|
services.AddSingleton<ITokenStorage, MauiSecureTokenStorage>();
|
|
services.AddSingleton(sp =>
|
|
{
|
|
var tokenStorage = sp.GetRequiredService<ITokenStorage>();
|
|
return new IronServicesClient(options, tokenStorage);
|
|
});
|
|
|
|
return services;
|
|
}
|
|
}
|