Dependency Injection

In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A “dependency” is an object that can be used, for example as a service. Instead of a client specifying which service it will use, something tells the client what service to use. The “injection” refers to the passing of a dependency (a service) into the object (a client) that would use it. The service is made part of the client’s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.

Dictionary-style settings as IOptions
Dictionary-style settings as IOptions
.NET Core / C#, Dependency Injection, IOptions

Dictionary-style settings as IOptions

I love how we can use appsettings.json files to configure applications in the .NET Core platform. The JSON-format feels a lot less bloated than the old XML appSettings config I used to work with. In this blog I’ll explore how to load a dictionary-style settings class as an IOption. This can be very useful when working with dependency injection.

Dependency injection (with IOptions) in Console Apps in .NET Core
Dependency injection (with IOptions) in Console Apps in .NET Core
.NET Core / C#, Console Application, Dependency Injection, IOptions

Dependency injection (with IOptions) in Console Apps in .NET Core

When you are used to building web applications, you kind of get hooked to the ease of Dependency Injection (DI) and the way settings can be specified in a JSON file and accessed through DI (IOptions). It’s only logical to want the same feature is your Console app.