Skip to content

derekgreer/conventional-options

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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