Implementing DI in a RemObjects DataAbstract .Net Core 8 app

I am trying to implement DI into a RemObjects DataAbstract .NET Core app. I have found a couple of articles that helped me understand:

It appears to be a bit incomplete. Here is what I am trying to implement (something like this):

public static int Main(string[] args)
{
    var host = CreateHostBuilder(args).Build();
    // Access IConfiguration from the host
    var configuration = host.Services.GetRequiredService<IConfiguration>();
    var serverSetting = configuration.GetSection("System");
    var database = configuration.GetSection("Databases");
    var monitor = host.Services.GetRequiredService<IOptionsMonitor<SystemSettings>>();
    monitor.OnChange(OnSettingsChanged);
  
  //Additional code here

}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((context, config) =>
    {
        config.SetBasePath(Directory.GetCurrentDirectory());
        config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
        config.AddJsonFile($"appsettings.{currentEnvironment}.json", optional: true);
    })
    .ConfigureServices((context, services) =>
    {
        services.Configure<SystemSettings>(context.Configuration.GetSection("Chronicle:System"));
        services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<SystemSettings>>().Value);
        services.AddSingleton<IOptionsMonitor<SystemSettings>, OptionsMonitor<SystemSettings>>();
    });
private static void OnSettingsChanged(SystemSettings systemSettings)
{
    Console.WriteLine("Settings changed:");
    Console.WriteLine($"CDN Enabled: {systemSettings.CDN}");
    // Handle other settings as needed
}

This allows me to monitor the changes made to the appsettings.json and track changes made the the appsettings.json reacting to those changes in program.cs file.
I am not sure how I would implement that in the DI for the ApplicationServer.

appSvr = new ApplicationServer(“DataAccess.Remote2”);
appSvr.DependencyResolver.RegisterSingleton(typeof(IConfiguration), configuration);

Not sure how to implement the event model. Any help is appreciated.

Hi,

I’m not sure that you can mix ApplicationHost Infrastucture (.NET) with Dependency Injection support (.NET) implementations.

but your DI implementation can be something like

var server := new ApplicationServer('ServerApp2');

var container := new SimpleContainer();
// not sure that you can use IConfiguration outside of ApplicationHost's infrastructure
// container.RegisterSingleton(typeof(IConfiguration), configuration);      
container.RegisterSDK(server.NetworkServer);
container.RegisterDataAbstract();
container.RegisterServices();
server.DependencyResolver := container;