public void Init(ApplicationSettings settings) { var serviceCollection = new ServiceCollection(); // initialize services (anything that is not actor framework specific) // like DDD/CQRS/ES stuff // remember that Actors should be transient and anything inside them must be transient // or singleton, any other lifecycle will cause troubles! var network = new ReliableNetworkSimulator(2, 10); serviceCollection.AddSingleton <INetworkSimulator>(network); serviceCollection.AddSingleton <IPersistence>(new InMemoryPersistence(new InMemoryPersistenceOptions { NetworkSimulator = network })); serviceCollection.AddSingleton <IStreamsFactory, StreamsFactory>(); serviceCollection.AddSingleton <IAggregateFactory, DefaultAggregateFactory>(); serviceCollection.AddTransient <IRepository, Repository>(); // Do NOT use singleton for this one, it has bugs with _trackingAggregate serviceCollection.AddTransient <RoomCommandHandler>(); serviceCollection.AddTransient <ProjectionEngine>(); // initialize the actor System switch (settings.ActorFramework) { case ActorFramework.Akka: _akkaApp = new AkkaApplication(); _akkaApp.Initialize("AkkaAppActorSystem", serviceCollection, settings.EndpointPost); _akkaApp.Start(); break; case ActorFramework.ProtoActor: break; } }
static IPersistence BuildStore(string store) { Console.WriteLine($"Selected store is {store}"); switch (store.ToLowerInvariant()) { case "memory": { var network = new ReliableNetworkSimulator(2, 10); return(new InMemoryPersistence(network, ObjectSerializer.Clone)); } case "mongo": { var options = new MongoStoreOptions { PartitionsConnectionString = Mongo, UseLocalSequence = true, PartitionsCollectionName = "partitions", SequenceCollectionName = "seq", DropOnInit = true, Serializer = new MongoCustomSerializer(), CustomizePartitionSettings = settings => { settings.MaxConnectionPoolSize = 5000; } }; var mongo = new MongoPersistence(options); mongo.InitAsync(CancellationToken.None).GetAwaiter().GetResult(); return(mongo); } } throw new Exception($"Invalid store {store}"); }