Skip to content

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

License

Notifications You must be signed in to change notification settings

KeesCBakker/keestalkstech-code-gallery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeesTalksTech Gallery Repository

This repository containers a lot of code samples for articles on my blog. It is easier to keep the code up to date when all of the items are grouped.

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

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<T>). It's only logical to want the same features in your Console app.

2. Simple JWT Access Policies for API security in .NET

Services can use their private key to communicate with our service. We can configure the access for each issuer using standard .NET claims.

3. Options Injection

Options themselves can be collections as well. This project shows how to use a Dictionary<string, string> and a List<string> as base classes for options. Both are supported by default.

4. .NET Console Application with injectable commands (System.CommandLine preview)

How to use System.CommandLine to build a CLI with commands and dependency injection.

5. Roman Numerals

Parsing Roman Numerals in C# is a good way to explore (implicit) operator overloading.

6. Handlebars.Net & JSON templates

I ❤️ Handlebars! So I was very very very happy to see that Handlebars was ported to .NET! It is a mega flexible templating engine as it can easily be extended. I'm working on a project where I need to parse objects via JSON templates to JSON strings. This blog will show how to instruct Handlebars to parse into JSON and add some nice error messages if your template fails.

8. Bypass Company Wallpaper as Local Admin

Looks like my organization wants to manage my background picture. But I'm a local admin, so let's see if we can still change that background picture. When I go to Setting > Personalization > Background, I see the message: "Some of these settings are managed by your organization." If you are an admin, you might be able to (temporarily) override the wallpaper, by editing your registry and triggering a refresh of the wallpaper. If you can, you can automate it using PowerShell.

12. Kiota and Resilience

My new years resolution for 2025 is not to write a custom implementation if I have an Open API specification availabe. Let's use Kiota to generate a client and add resilience with the Microsoft Microsoft.Extensions.Resilience package (which is basically a wrapper around Polly).

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published