Skip to content

derekgreer/conventional-options

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conventional Options

Conventional Commits

ConventionalOptions is a convenience library for working with Microsoft's .Net Core configuration API.

The goal of ConventionalOptions is to simplify creation and use of POCO option types.

Quickstart

Step 1

Install ConventionalOptions for the target DI container:

$> nuget install ConventionalOptions.DependencyInjection

Step 2

Add Microsoft's Options feature and register option types:

services.AddOptions();
services.RegisterOptionsFromAssemblies(Assembly.GetExecutingAssembly());

Step 3

Create an Options class:

    public class OrderServiceOptions
    {
        public string StringProperty { get; set; }
        public int IntProperty { get; set; }
    }

Step 4

Provide a corresponding configuration section (e.g. in appsettings.json):

{
  "OrderService": {
    "StringProperty": "Some value",
    "IntProperty": 42
  }
}

Step 5

Inject the options into types resolved from the container:

    public class OrderService
    {
        public OrderService(OrderServiceOptions options)
        {
            // ... use options
        }
    }

That's it!

For more examples, see the documentation or browse the specifications.

About

A configuration options convenience library

Resources

Stars

Watchers

Forks

Packages

No packages published