Integration Guide
Connect your application to the Monaiq platform.
Prerequisites & Packages
Install the core package to get started. This package includes everything you need to communicate with the Monaiq platform.
dotnet add package Sidub.Licensing.Client
Configuration
Add your credentials to your appsettings.json or environment variables.
{
"LicensingServiceOptions": {
"EncodedCredential": "<encoded-credential>",
"LicenseServiceUri": "https://api.monaiq.com/licensing",
"ConsumptionServiceUri": "https://api.monaiq.com/consumption",
"BillablePlanId": "<plan-guid>",
"BillableResourceId": "<resource-guid>"
}
}
Dependency Injection
Register the Monaiq services in your application startup (e.g., Program.cs).
using Microsoft.Extensions.Options;
using Sidub.Platform.Core.Services;
using Sidub.Licensing.Client;
using Sidub.Licensing.Client.Extensions;
// ==== SIDUB-LICENSING-BEGIN: DI ====
builder.Services.Configure<LicensingServiceOptions>(
builder.Configuration.GetSection(nameof(LicensingServiceOptions)));
builder.Services.AddSidubPlatform(sp =>
{
var options = sp.GetRequiredService<IOptionsSnapshot<LicensingServiceOptions>>().Value
?? throw new InvalidOperationException("Missing LicensingServiceOptions");
var registry = new InMemoryServiceRegistry();
registry.RegisterLicense(options);
return registry;
});
builder.Services.AddSidubLicensing();
// ==== SIDUB-LICENSING-END: DI ====
Runtime References
Resolve the licensing service and create a reference for your application component.
using Sidub.Licensing.Services;
using Sidub.Platform.Core.Services;
// ==== SIDUB-LICENSING-BEGIN: REFS ====
var licensing = app.Services.GetRequiredService<ILicensingService>();
var licensingRef = LicensingServiceReference.ServiceReference; // global reference provided by the SDK
public sealed record ChatServiceReference(string Name) : ServiceReference(Name);
// ==== SIDUB-LICENSING-END: REFS ====
Enforce Features
Use the SDK to check if a user has access to a feature or to enforce rate limits.
Access Gate
Check if a feature is enabled.
// ==== SIDUB-LICENSING-BEGIN: ACCESS-GATE ====
using Sidub.Licensing.Services;
using Sidub.Licensing.Features;
const string AccessKey = "chat.access";
bool allowed = await licensing.AssertLicense(
licensingRef, context,
ServiceAccessLicenseAssertion.Create(AccessKey));
if (!allowed)
{
logger.LogWarning("Access not licensed for {AccessKey}", AccessKey);
return;
}
// ==== SIDUB-LICENSING-END: ACCESS-GATE ====
Rate Limit
Check if the user has quota remaining.
// ==== SIDUB-LICENSING-BEGIN: RATE-LIMIT ====
using Sidub.Licensing.Features;
const string RateKey = "chat.rate";
// Resolve the feature for the consumption operation
var feature = await licensing.GetLicenseFeature<RateLimitLicenseFeature>(licensingRef, context, RateKey)
?? throw new InvalidOperationException($"Rate feature '{RateKey}' not found.");
// Record consumption and assert within budget
var op = new RateLimitLicenseFeatureOperation(feature, 1);
await licensing.PerformOperation<RateLimitLicenseFeature, RateLimitLicenseFeatureState>(licensingRef, context, op);
var withinBudget = await licensing.AssertLicense(licensingRef, context, RateLimitLicenseAssertion.Create(RateKey));
if (!withinBudget)
{
throw new InvalidOperationException("Rate limit exceeded. Please try again later.");
}
// SAFE: continue with the protected action
// ==== SIDUB-LICENSING-END: RATE-LIMIT ====