An open API service indexing awesome lists of open source software.

https://github.com/arnab-developer/advance-consoleapp

Console app with DI and configuration support
https://github.com/arnab-developer/advance-consoleapp

Last synced: 10 months ago
JSON representation

Console app with DI and configuration support

Awesome Lists containing this project

README

          

# Console app with DI and configuration support

This is an example console application to show how we can use dependency injection and
configuration support in console app with .NET Core hosting.

This is a normal console application. I have added `Microsoft.Extensions.Hosting` nuget
package to take advantage of dependency injection, configuration etc in it.

```xml

```

Now I can use dependency injection in the `Main` method.

```c#
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddMediatR(typeof(OrderController));
services.AddDbContext(option =>
option.UseSqlServer(context.Configuration.GetConnectionString("ConsoleApp1DbConStr")));
})
.Build();
```