C#C
C#12mo ago
VoidPointer

Appsettings not mapping to Options class

I could probably have worded the question better, but please bear with me. Also, this is not my code, and probably has not been set up properly, but other team members are all really busy.

I see this in the Program class:
        public static IWebHost CreateWebHostBuilder(string[] args)
        {
            var config = new ConfigurationBuilder().AddCommandLine(args).Build();
             return WebHost.CreateDefaultBuilder(args)
...
                     .UseConfiguration(config)
                     .Build()
                     .InitializeIdentityDb<ApplicationUser, ApplicationRole>();
        }

and then ` is defined as such: ```cs public static IWebHost InitializeIdentityDb<TUser, TRole>(this IWebHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var options = services.GetRequiredService<IOptions<CassandraOptions>>(); ... var initializer = new DbInitializer(session); initializer.Initialize<TUser, TRole>(options.Value); return host; } } ``` Then CassandraOptions is declared as: ```cs public class CassandraOptions { public List<string> ContactPoints { get; set; } public CassandraCredentials Credentials { get; set; } public string KeyspaceName { get; set; } public Dictionary<string, string> Replication { get; set; } = null; public bool DurableWrites { get; set; } = true; public CassandraQueryOptions Query { get; set; } } ``` Now at my breakpoint on initializer.Initialize<TUser, TRole>(options.Value), I see that options is not populated. Colleagues reckon it's supposed to be populated from command line arguments, but how do I define nested values like CassandraOptions` with command line params?
Was this page helpful?