-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
57 lines (46 loc) · 1.7 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
using BE.CQRS.Domain;
using BE.CQRS.Domain.Configuration;
using BE.CQRS.Domain.Denormalization;
using BE.CQRS.Domain.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
using NetCoreConsoleSample.Domain;
using NetCoreConsoleSample.Domain.Commands;
using NetCoreConsoleSample.Domain.States;
namespace NetCoreConsoleSample
{
class Program
{
static Random Randomizer = new Random((int) DateTime.Now.TimeOfDay.TotalMilliseconds);
static async Task Main(string[] args)
{
Console.WriteLine("Starting application...");
Console.WriteLine("Adding CQRS...");
var services = CQRSBooter.CreateServiceCollectionWithLogger();
services
.AddEventSource()
.AddDenormalizer();
var serviceProvider = services.BuildServiceProvider();
var repo = serviceProvider.GetRequiredService<IDomainObjectRepository>();
var customer = CreateCustomerObject();
await repo.SaveAsync(customer);
var persistedCustomer = await repo.Get<Customer>(customer.Id);
Console.WriteLine($"Persisted customer name: {persistedCustomer.State<NameState>().Name}");
}
private static Customer CreateCustomerObject()
{
Customer customer;
var id = Randomizer.Next();
customer = new Customer(id.ToString());
customer.CreateNewCustomer(new CreateCustomerFromConsoleCommand()
{
Name = "Contoso"
});
return customer;
}
}
}