forked from BoasE/BE.CQRS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CQRSBooter.cs
40 lines (36 loc) · 1.35 KB
/
CQRSBooter.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
using System;
using AspNetCoreSample.Domain;
using BE.CQRS.Data.MongoDb;
using BE.CQRS.Di.AspCore;
using BE.CQRS.Domain.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
namespace AspNetCoreSample
{
public static class CQRSBooter
{
public static IServiceCollection AddCqrs(this IServiceCollection serivces, IConfiguration config)
{
Console.WriteLine("Adding CQRS...");
string url = config["CustomerDatabase:MongoDb:Host"];
string db = config["CustomerDatabase:MongoDb:Name"];
Console.WriteLine($"ES DB: {url} - {db}");
IMongoDatabase mongodb = new MongoClient(url).GetDatabase(db);
serivces.AddEventSource(
new EventSourceConfiguration()
.SetDomainObjectAssemblies(typeof(Customer).Assembly)
.SetServiceProviderActivator()
.SetMongoDomainObjectRepository(mongodb)
.SetConventionBasedInMemoryCommandBus());
Console.WriteLine($"CQRS added");
return serivces;
}
public static IApplicationBuilder UseCqrs(this IApplicationBuilder app)
{
app.UseServiceProviderActivator();
return app;
}
}
}