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
- Host: GitHub
- URL: https://github.com/arnab-developer/advance-consoleapp
- Owner: Arnab-Developer
- License: mit
- Created: 2020-11-07T13:21:31.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T11:54:43.000Z (over 4 years ago)
- Last Synced: 2025-01-17T02:24:20.772Z (12 months ago)
- Language: C#
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
```