-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModulesExample.cs
More file actions
31 lines (26 loc) · 1.45 KB
/
Copy pathModulesExample.cs
File metadata and controls
31 lines (26 loc) · 1.45 KB
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
using Codefinity.EventEmitter.Sample.Infrastructure;
using Codefinity.EventEmitter.Sample.Inventory;
using Codefinity.EventEmitter.Sample.Orders;
using Codefinity.EventEmitter.Sample.Shipping;
using Microsoft.Extensions.DependencyInjection;
namespace Codefinity.EventEmitter.Sample.Examples;
/// <summary>
/// An event travels Orders → Inventory → Shipping across three assemblies. No module references a
/// service of another module; each one only knows the event types it publishes or listens for.
/// </summary>
internal static class ModulesExample
{
public static async Task RunAsync()
{
await using var app = await ExampleApp.StartAsync(services => services
.AddOrdersModule() // EventEmitter.Sample.Orders.dll
.AddInventoryModule() // EventEmitter.Sample.Inventory.dll
.AddShippingModule()); // EventEmitter.Sample.Shipping.dll
app.Say("Completing order-1. OrderService only has an IEventPublisher; it can't see Inventory or Shipping.");
await app.InScopeAsync(sp => sp.GetRequiredService<OrderService>().CompleteAsync("order-1", "alice"));
app.Say("CompleteAsync has returned. Inventory and Shipping run in the background, on other threads:");
var carrier = app.Get<CarrierGateway>();
await app.WaitUntilAsync(() => carrier.Shipments.ContainsKey("order-1"));
app.Say("OrderCompleted reached Inventory, whose StockReserved event reached Shipping.");
}
}