.Net Core Console Application IoC

By | 2019-05-07

The default setup for .Net Core MVC application is to use IoC. You get a Startup.cs file created that contains boilerplate code for IoC.

If you want to use the builtin IoC with .Net Core you have to write it yourself. Luckily the HostBuilder makes this easy.

You need to add nuget packages:

  • Install-Package Microsoft.Extensions.Hosting
  • Install-Package Microsoft.Extensions.DependencyInjection
  • Install-Package Microsoft.Extensions.Configuration
  • Install-Package Microsoft.Extensions.Configuration.Json
  • Install-Package Microsoft.Extensions.Configuration.CommandLine
  • Install-Package Microsoft.Extensions.Logging
  • Install-Package Microsoft.Extensions.Logging.Console

Main.cs

Startup.cs

Config example

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.