После просмотра / чтения некоторых руководств о шаблоне параметров в. net для привязки ваших настроек к модели c#, у меня возник этот конкретный вопрос о привязке настройки «Microsoft.Hosting.Lifetime» к модели.
![enter image description here](https://i.stack.imgur.com/PCAHh.png)
Situation
I know how to bind settings to a model via the option pattern.
So having the appsettings.json file like
"FeatureFlags": {
"IsFeature1Enabled": "false",
"IsFeature2Enabled": "false",
"IsFeature3Enabled": "true"
}
would result in code like:
model:
public class FeatureFlagOptions
{
public bool IsFeature1Enabled { get; set; } = false;
public bool IsFeature2Enabled { get; set; } = false;
public bool IsFeature3Enabled { get; set; } = false;
}
startup.cs:
private void SetUpAppSettingsModels(IServiceCollection services)
{
services.Configure(options => Configuration.GetSection("FeatureFlags").Bind(options));
}
class with DI:
private readonly FeatureFlagOptions _featureFlags;
public ClassNameHere(IOptions featureFlags)
{
_featureFlags = featureFlags.Value;
}
Question
If you start a new web application and choose for example a web api, the standard appsettings will contain the appsetting “Microsoft.Hosting.Lifetime”. Like in the picture in the beginning.
So how should I implement that setting in my model?
I Googled a lot, searched on stackoverflow and even my favorite blog writer Rick Strahl (https://weblog.west-wind.com/posts/2017/dec/12/easy-configuration-binding-in-aspnet-core-revisited) пропустил часть с разделом логирования. Я надеюсь, что кто-нибудь сможет мне помочь с этим. Спасибо!
Почему мне нужна эта собственность ?: по причинам;)