> For the complete documentation index, see [llms.txt](https://vostok.gitbook.io/configuration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vostok.gitbook.io/configuration/basic-scenarios/make-settings-required.md).

# Make settings required

**Requires**: [abstractions module](/configuration/modules/abstractions.md).

By default all settings are optional; that is, absence of relevant data in the [source](/configuration/concepts-and-basics/configuration-sources.md) results in default values during [binding](/configuration/concepts-and-basics/binding-nodes-to-models.md) and does not produce errors.&#x20;

Some parts of configuration may be crucial to the application to the point that it's pointless to start without them being initialized. These fields and properties should be annotated with `[Required]` attribute:

```
class MySettings 
{
    [Required]
    public string DbConnectionString { get; }
    
    [Required]
    public MySecrets Secrets { get; }
}

class MySecrets 
{
    public string ApiKey { get; }
    public string Login { get; }
    public string Password { get; }
}
```

```
provider.Get<MySettings>(); // will throw if DbConnectionString or Secrets are not initialized 
```

###

### Changing defaults

Default behavior can be inverted in the scope of a type with `[RequiredByDefault]` attribute. Individual fields and properties can then be made optional with `[Optional]` attribute:

```
[RequiredByDefault]
class MySettings 
{
    [Optional]
    public TimeSpan Timeout { get; } = TimeSpan.FromSeconds(30);
}
```

###

### Related pages

{% content-ref url="/pages/-M6UVVWxjimC0yLfXc\_P" %}
[Obtain settings from provider](/configuration/basic-scenarios/obtain-settings-from-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UVXzWRFlbId1t7QdO" %}
[Observe settings via provider](/configuration/basic-scenarios/observe-settings-via-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/-M6UQlGKGPuVt1P3lsHf" %}
[Binding nodes to models](/configuration/concepts-and-basics/binding-nodes-to-models.md)
{% endcontent-ref %}
