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:
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?8 Replies
Unknown User•7h ago
Message Not Public
Sign In & Join Server To View
unrelated to the problem but also odd that
CreateWebHostBuilder
returns IWebHost
rather than IWebHostBuilder
. Either change the method's name or don't build inside the methodUnknown User•7h ago
Message Not Public
Sign In & Join Server To View
Where is
CassandraOptions
registered?
I'd expect to see something like builder.Services.Configure<CassandraOptions>(builder.Configuration.GetSection("Cassandra"));
Unknown User•6h ago
Message Not Public
Sign In & Join Server To View
You don't need the bind afaik.
Unknown User•6h ago
Message Not Public
Sign In & Join Server To View
Sorry guys, the use of options in this project was royally screwed up be whoever tried it, so they reverted to manually reading env vars for cassandra, and mine weren't getting read. I'll close this now as a bad joke.