Managing .NET App Configuration With The Options Pattern In ASP.NET Core

preview_player
Показать описание

In this video, we will explore the Options pattern in ASP.NET Core and how we can use it to manage our application configuration. The options pattern is very straightforward to use, and we have one of three interfaces to choose from:
- IOptions
- IOptionsSnapshot
- IOptionsMonitor

All of them are slightly different, and I will try to highlight the most important aspects of each.

How To Use The Options Pattern In ASP.NET Core 7:

Adding Validation To The Options Pattern In ASP.NET Core

Join my weekly .NET newsletter:

Read my Blog here:

Subscribe for more:

Chapters
0:00 How to use IOptions
3:45 How to use IOptionsSnapshot and IOptionsMonitor
6:43 Configuring options pattern with IConfigureOptions
Рекомендации по теме
Комментарии
Автор

Thanks Milan
Another great video is to show how to use config with multiple appsettings.json for multiple environments

mahmoudalaskalany
Автор

Really great and quick overview of concept. Just in time. Appreciate it

vinodcs
Автор

Awesome, most people don't know about the Snapshot and Monitor options.

It's a very good way to get real time config changes from external providers like Azure Configuration or Amazon Cloud.

However, there aren't a lot of scenarios where you can use monitored options. Most libraries don't support it.

MarcusKaseder
Автор

Muy buno tu video ( Very good your video). Hello, from Dominican Republic !

DanyAracena
Автор

Love to see a bonus video where you are pulling configuration from Azure/AWS. AWS would be SSM Parameters. I assume Azure has something similar.

pilotboba
Автор

Just when I was about to investigate about this.

robertmrobo
Автор

IOptionsSnapshot is very useful. It is used to use named options when you have multiple instances of the same type.

SKglitches
Автор

Thank you, Milan. This video is very informative.

arjundate
Автор

Extremely useful video, thanks Milan 👍

omerkulahli
Автор

I appriciate much your work. Thank you again for this video.

kodindoyannick
Автор

Hi, Milan. Nice video, as always. I was wondering which theme are you using in your Visual Studio

menganodetal
Автор

I think you can easily make a video here about how to bind more complex types, or collections from arrays in the json file. It's a common question online I noticed.

MrJ
Автор

How to use the configuration (good patterns and practices) in net5-6-7?
We have several application domains: Server Blazor, Unit Test (MSTest), Console application (or Azure WebJobs).
We have common libraries that use the application domains.
Simplifying, for example, Core, and Logic.
In Logic, there are business logic classes BLL: BL1 can reference or call BL2, BL3, BL4, and them other classes.

We can use in the configuration: connections strings, mail, api rest credential, etc.
For example, BL2 uses configuration to send an email, BL3 uses configuration to use a rest api.

If, for example, we use IOptions, <ConfigurationMail>we have to inject it into BL1, then "pass" it (like parameter) to classes BL2, BL3, ...

In the Startup, code like "services.Configure" for IOptions. And "services.AddSingleton" for BL1.

From the *.razor you can also inject: @inject IOptions<ConfigurationMail> configMail

Another way: use ConfigurationBuilder to access the appesttings.json.
Maybe use a Nuget ConfigurationManager package for net core (net5-6-7)

kiquenet
Автор

Thank you for your videos. I have a request, can you please explain your project structure, the pattern you are using, why these classes needed, how dependency injection works in this project ect.. . I think who are watching your videos are average programmers and want to improve their coding style. Thanks in advance

ethan_hunt
Автор

Super Milane. Imas li primjer kako se implementira Options Pattern u Azure Functions v4? Nigdje nema fin primjer. Tako da je odlična prilika da ti budeš prvi 😊

LencoTB
Автор

nice video.
Just want to know how did you remove extra indentations at 07:00

i.t.
Автор

Realy good this video!
About console apps? it looks like the ValidateOnStart does not work like the web you can make an example? Also is it possible to have multiple sections nested in the options?

DanStpTech
Автор

Hey Milan. Does the IOptions class support working with records? If you use IOptions with records instead of plain old classes you will have problems. I don't know why ...

neroamayo
Автор

How about reading them in program.cs and bind them to objects then register in the container and inject them wherever you need them in your application?

malikehsan
Автор

Hi, is there any good solution for storing configuration and secerets (passwords, kyes, ...) for .NET core apps? appsettings.json is not best for those configs, I know thate there is some Vault for configs in Azure, but is there anything for in house services/containers/web apps? Some kind of "config server" or some store which can be used? Or best solution is to write own config provider and config store?