- Add net9.0 to TargetFrameworks for non-MAUI apps - Create FileSystemLicenseCache for file-based license storage - Create Platforms/Net9/MachineIdentifier using Environment APIs - Add conditional compilation for MAUI vs non-MAUI platforms - Update ServiceCollectionExtensions for conditional DI registration - Bump version to 1.2.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace IronLicensing.Client.Extensions;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds IronLicensing client services to the service collection
|
|
/// </summary>
|
|
/// <param name="services">The service collection</param>
|
|
/// <param name="configure">Configuration action for licensing options</param>
|
|
/// <returns>The service collection for chaining</returns>
|
|
public static IServiceCollection AddIronLicensing(this IServiceCollection services, Action<LicensingOptions> configure)
|
|
{
|
|
services.Configure(configure);
|
|
|
|
// Core services
|
|
services.AddHttpClient<ILicenseManager, LicenseManager>();
|
|
services.AddSingleton<IMachineIdentifier, MachineIdentifier>();
|
|
services.AddSingleton<ISignatureVerifier, RsaSignatureVerifier>();
|
|
|
|
#if MAUI
|
|
// Use SecureStorage on MAUI platforms
|
|
services.AddSingleton<ILicenseCache, SecureStorageLicenseCache>();
|
|
#else
|
|
// Use file system cache on server/console apps
|
|
services.AddSingleton<ILicenseCache, FileSystemLicenseCache>();
|
|
#endif
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds IronLicensing client services with simplified configuration
|
|
/// </summary>
|
|
/// <param name="services">The service collection</param>
|
|
/// <param name="publicKey">Your public API key (pk_live_xxx or pk_test_xxx)</param>
|
|
/// <param name="productSlug">Your product slug identifier</param>
|
|
/// <returns>The service collection for chaining</returns>
|
|
public static IServiceCollection AddIronLicensing(this IServiceCollection services, string publicKey, string productSlug)
|
|
{
|
|
return services.AddIronLicensing(options =>
|
|
{
|
|
options.PublicKey = publicKey;
|
|
options.ProductSlug = productSlug;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds IronLicensing client services with custom API URL (for self-hosted installations)
|
|
/// </summary>
|
|
/// <param name="services">The service collection</param>
|
|
/// <param name="publicKey">Your public API key</param>
|
|
/// <param name="productSlug">Your product slug identifier</param>
|
|
/// <param name="apiBaseUrl">Custom API base URL</param>
|
|
/// <returns>The service collection for chaining</returns>
|
|
public static IServiceCollection AddIronLicensing(
|
|
this IServiceCollection services,
|
|
string publicKey,
|
|
string productSlug,
|
|
string apiBaseUrl)
|
|
{
|
|
return services.AddIronLicensing(options =>
|
|
{
|
|
options.PublicKey = publicKey;
|
|
options.ProductSlug = productSlug;
|
|
options.ApiBaseUrl = apiBaseUrl;
|
|
});
|
|
}
|
|
}
|