|
1 | 1 | using Akka.Actor;
|
2 | 2 | using Akka.Hosting;
|
3 |
| -using Akka.Persistence.SqlServer.Hosting; |
| 3 | +using Akka.Persistence.Sql.Config; |
4 | 4 | using CqrsSqlServer.Backend.Actors;
|
5 | 5 | using CqrsSqlServer.DataModel;
|
6 | 6 | using CqrsSqlServer.Shared;
|
| 7 | +using CqrsSqlServer.Shared.Events; |
7 | 8 | using CqrsSqlServer.Shared.Serialization;
|
8 | 9 | using CqrsSqlServer.Shared.Sharding;
|
9 | 10 | using Microsoft.EntityFrameworkCore;
|
10 | 11 | using Microsoft.Extensions.Configuration;
|
11 | 12 | using Microsoft.Extensions.DependencyInjection;
|
12 | 13 | using Microsoft.Extensions.Hosting;
|
13 |
| -using Petabridge.Cmd.Cluster; |
14 |
| -using Petabridge.Cmd.Cluster.Sharding; |
| 14 | +using Akka.Persistence.Sql.Hosting; |
| 15 | +using LinqToDB; |
15 | 16 | using Petabridge.Cmd.Host;
|
16 | 17 |
|
17 | 18 | var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";
|
|
40 | 41 | {
|
41 | 42 | builder
|
42 | 43 | .AddAppSerialization()
|
43 |
| - .WithSqlServerPersistence(connectionString) |
| 44 | + .WithSqlPersistence(connectionString: connectionString, |
| 45 | + providerName: ProviderName.SqlServer2019, |
| 46 | + databaseMapping: DatabaseMapping.SqlServer, |
| 47 | + tagStorageMode: TagMode.TagTable, |
| 48 | + journalBuilder: journalBuilder => |
| 49 | + { |
| 50 | + journalBuilder.AddWriteEventAdapter<MessageTagger>("product-tagger", |
| 51 | + new[] { typeof(IProductEvent) }); |
| 52 | + }) |
44 | 53 | .WithActors((system, registry, resolver) =>
|
45 | 54 | {
|
| 55 | + // in a real world scenario, this actor would be an Akka.Cluster.Sharding ShardRegion |
46 | 56 | var parentActor =
|
47 | 57 | system.ActorOf(
|
48 | 58 | Props.Create(() => new GenericChildPerEntityParent(new ProductMessageRouter(),
|
49 | 59 | ProductTotalsActor.GetProps)), "productTotals");
|
50 |
| - |
| 60 | + |
51 | 61 | registry.Register<ProductMarker>(parentActor);
|
52 | 62 | })
|
53 |
| - .AddPetabridgeCmd(cmd => |
| 63 | + .WithActors((system, registry, resolver) => |
54 | 64 | {
|
55 |
| - |
| 65 | + // in a real-world scenario, this projector would be a cluster singleton or would run in its own process |
| 66 | + var projectionsActor = system.ActorOf(resolver.Props<ProductProjectorActor>(), "projections"); |
56 | 67 | })
|
| 68 | + .AddPetabridgeCmd(cmd => { }) |
57 | 69 | .AddStartup((system, registry) =>
|
58 | 70 | {
|
59 |
| - new FakeDataGenerator().Generate(system, registry, 100); |
60 |
| - });; |
| 71 | + var seedDb = hostContext.Configuration.GetValue<bool>("SeedDb"); |
| 72 | + if (seedDb) |
| 73 | + new FakeDataGenerator().Generate(system, registry, 100); |
| 74 | + }); |
| 75 | + ; |
61 | 76 | });
|
62 | 77 | });
|
63 | 78 |
|
|
0 commit comments