top of page

Microsoft .NET API Startup and SDK integration

Updated: Jul 23, 2023

Step 1: Update appsettings.json

  1. Update your appsettings.json file with the necessary configurations for RelFast:

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
  "AllowedHosts": "*",
  "RelFastOauthOptions": {
    "AuthorityTokenEndpoint": "",
  "RelFastOptions": {
    "CoreApiEndpoint": "",
  "RelFastConfigurationOptions": {
    "CacheIntervalInMilliSeconds": 0,
    "EnableCaching": false,
    "FallBack": 1

Step 2: Install NuGet Packages

Add the following NuGet packages to your .NET project:

  • RelFast.SDK

  • RelFast.SDK.OAuth

Step 3: Create an Extension Method for RelFastClient

  1. Create an extension method to bootstrap the RelFastClient in your project. Add the following code to ServiceCollectionExtensions.cs:

using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using RelFast.SDK.Abstract.Configuration;
using RelFast.SDK.Core.Configuration;
using RelFast.SDK.OAuth.Concrete;
using RelFast.SDK.OAuth.Model;
using System.Net.Http;

namespace YourProjectNamespace
    public static class ServiceCollectionExtensions
        public static void BootStrapRelFastClient(this IServiceCollection services, IConfiguration configuration)
            // Create a http client
            var client = new HttpClient();
            // Create an in-memory cache. This is required to store information for up to 30 seconds.
            var cache = new MemoryCache(new MemoryCacheOptions());

            // Create the RelFastOauthOptions
            var relFastOauthOptions = new RelFastOauthOptions();

            // Create the RelFastOptions
            var relFastOptions = new RelFastOptions();

            // Create the RelFastClient
            services.AddSingleton<IRelFastClient>(sp =>
                new RelFastClient(sp.GetRequiredService<IOptions<RelFastOptions>>(),
                                  new OAuthService(cache, sp.GetRequiredService<IOptions<RelFastOauthOptions>>(), client)));

Step 4: Use RelFastClient in Startup

  1. Modify your Program.cs to use the RelFastClient and RelFastConfigurationOptions from appsettings.json. Add the following code:

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using YourProjectNamespace.FlagOptions;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at

// Bootstrap the RelFastClient

// Configure options for DI. Pass the type based on what is configured in appsettings.json.

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())





Step 5: Use RelFastConfigurationOptions in Your Code

  1. Now you can use the RelFastConfigurationOptions in your controllers or other classes like this:

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using YourProjectNamespace.FlagOptions;
using RelFast.SDK.Abstract.Configuration;

namespace YourProjectNamespace.Controllers
    public class SampleController : ControllerBase
        private readonly IRelFastClient _relFastClient;
        private readonly RelFastConfigurationOptions<int> _configurationOptions;

        public SampleController(IRelFastClient relFastClient, IOptions<RelFastConfigurationOptions<int>> configurationOptions)
            _relFastClient = relFastClient;
            _configurationOptions = configurationOptions.Value;

        public IActionResult Get()
            // Retrieve the configuration value using the RelFastClient
            var configurationValue = _relFastClient.GetConfigurationValueAsync<int>(_configurationOptions).Result;

            // Your logic here...
            return Ok(configurationValue);

Now you have successfully integrated the RelFast SDK into your .NET application, and you can use it to fetch configurations from the RelFast service. Remember to replace the placeholders (e.g., YOUR_RELFAST_CLIENT_ID_ENV_VARIABLE) with actual values from your environment.

Recent Posts

See All


In the context of the example(Insurance company) provided, an "application" in Relfast refers to a logical grouping of related...

Create a SDK client

To create a new client ID and secret to be used as part of SDK calls in the RelFast portal, follow the step-by-step instructions below....

Secret rotation

To create a configuration that is a secret and use RelFast to easily rotate it, follow the step-by-step instructions below. Please ensure...

bottom of page