-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathProgram.cs
35 lines (28 loc) · 1.14 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// See https://aka.ms/new-console-template for more information
using System.Drawing;
using MediatorPattern;
using MediatorPattern.Infrastructure;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
Console.WriteLine("Legend:");
ColorConsole.WriteLineCommandHandler("Command - Handlers are blue");
ColorConsole.WriteLineQueryHandler("Query - Handlers are yellow");
ColorConsole.WriteLineProgram("Program code is green");
ColorConsole.WriteLineRepository("Repository code is magenta");
Console.WriteLine("------------------------");
Console.WriteLine();
var serviceProvider = CreateServiceProvider();
await serviceProvider.GetRequiredService<Execution>().RunAsync();
ServiceProvider CreateServiceProvider()
{
var collection = new ServiceCollection();
// This will execute our main logic
collection.AddScoped<Execution>();
// This comes from the MediatR package.
// It looks for all commands, queries and handlers and registers
// them in the container
collection.AddMediatR(typeof(Program).Assembly);
// Our repository
collection.AddScoped<UserRepository>();
return collection.BuildServiceProvider();
}