Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 1.49 KB

README.md

File metadata and controls

66 lines (48 loc) · 1.49 KB

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.