Skip to main content

.NET

Project Information

Installation

dotnet add package QuantumDMN.Sdk

Usage

using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using QuantumDMN.Sdk.Api;
using QuantumDMN.Sdk.Client;
using QuantumDMN.Sdk.Extensions;
using QuantumDMN.Sdk.Model;

namespace Example
{
class Program
{
static async Task Main(string[] args)
{
// Configuration
var apiUrl = "https://api.quantumdmn.com";
var authUrl = "https://auth.quantumdmn.com";
var keyFile = "path/to/service-user.json";
var projectId = "YOUR_DMN_PROJECT_ID";
var zitadelProjectId = "YOUR_ZITADEL_PROJECT_ID";
var definitionId = "YOUR_DEFINITION_ID";

try
{
// 1. Get Token
var tokenProvider = new ZitadelTokenProvider(keyFile, authUrl, zitadelProjectId);
var token = await tokenProvider.GetTokenAsync();

// 2. Setup DI and API
var services = new ServiceCollection();
services.AddApi(config =>
{
config.AddApiHttpClients(client =>
{
client.BaseAddress = new Uri(apiUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
});
});

using var provider = services.BuildServiceProvider();
var api = provider.GetRequiredService<IDefaultApi>();

// 3. Prepare Context
var feelContext = new Dictionary<string, FeelValue>
{
{ "RequestedAmt", 1000 }
};

// 4. Evaluate
var engine = new DmnEngine(api, projectId);
var result = await engine.EvaluateAsync(definitionId, feelContext);

Console.WriteLine("Result:");
Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true }));
}
catch (Exception e)
{
Console.Error.WriteLine($"Error: {e.Message}");
}
}
}
}