I’m not sure what’s happened, but anytime I call AppSettings.Get<EmailConfig>("Email")
, the object returned is null. This is in my main AppHostBase project (React).
I’m using the new NetCoreAppSettings(Configuration).
The strange thing is it works in my other root project (a standalone host that runs in a non-http environment, BasicAppHost, strictly for MQ services).
Setup of Non-working project
appsettings.json
{
"ConnectionStrings": {
"MainDatabase": "....."
},
"servicestack": {
"license": "...."
},
"Environment": "Local",
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
},
"Email": {
"From": "noreply@myapp.com",
"ApiKey": "EMPTY"
}
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
Configuration = builder.Build();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions()
{
HotModuleReplacement = true,
ReactHotModuleReplacement = true
});
}
app.UseServiceStack(new AppHost()
{
AppSettings = new MultiAppSettings(
new NetCoreAppSettings(Configuration)
)
});
}
public class AppHost : AppHostBase
{
public AppHost() : base("MyApp", typeof(PacketService).Assembly) { }
// Configure your AppHost with the necessary configuration and dependencies your App needs
public override void Configure(Container container)
{
SetConfig(new HostConfig
{
AddRedirectParamsToQueryString = true,
});
container.Register<IPasswordHasher<User>>(
new PasswordHasher<User>(new OptionsWrapper<PasswordHasherOptions>(new PasswordHasherOptions()
{
CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2
})));
container.Register<IPasswordHasher>(new CustomPasswordHasher(container.Resolve<IPasswordHasher<User>>()));
var emailSEttings = AppSettings.Get<EmailConfig>("Email"); // This is null
this.AddDatabase();
this.AddPlugins();
this.AddEmail();
this.AddProtection();
JsConfig.DateHandler = DateHandler.ISO8601;
}
}
EmailConfig.cs
public class EmailConfig
{
public string From { get; set; }
public string ApiKey { get; set; }
}
When I Debug AppSettings in AppHost.Configure, I see the NetCoreAppSettings, which lets me dig down into the values and Email:From, Email:ApiKey are in fact there.
Have I set something up wrong?
I’m using ServiceStack version 5.0.2