Better Defect Reduction: AI Applications in Your Quality Engineering Maturity Journey
The next time you sit down with your Chief Innovation Officer, bring up quality maturity as an agenda item. Artificial intelligence (AI) exists with …
READ MOREOptions pattern provides an elegant and an easy way for you to load your application configurations into your classes at runtime and access your configuration values from instance of the class rather then injection IConfiguration service. To use the options pattern in ASP.NET Core, you need to install the Microsoft.Extensions.Options.ConfigurationExtensions nuget package.
To get the maximum benefit of using the options pattern, you would typically want to use separate classes to represent a group of related settings in isolation.
To understand the options pattern configuration, consider the following example of a IntegrationSettings section in your appsettings.json file.
Inorder to use the options pattern to load the configurations in to a class at runtime, you need to create a class as below to hold the values loaded from the configurations.
You can now use the configure extension method of IServiceCollection to bind your settings class to your configuration as shown below.
Now to read configuration data in the controller. You can use the IOptions
As shown above, you can access your configuration values from your _settings class similar to how you access any data from another class and you no longer need to inject IConfigurations class as a dependency to your controller or service.
Next time when you are dealing with configurations use the option patterns as it brings lots of flexibility to manage your configurations data.
Using Options Pattern helps you isolate your configurations to the code where its required.
Thank you!
The next time you sit down with your Chief Innovation Officer, bring up quality maturity as an agenda item. Artificial intelligence (AI) exists with …
READ MOREAI has been an anticipated technological breakthrough, taking over most manual white-collar jobs today. PwC’s Global AI Study reveals that AI will …
READ MORE