private static ISiloHost ConfigureSilo() { var builder = new ConfigurationBuilder() .AddJsonFile($"appsettings.json", true, true) .AddJsonFile($"appsettings.{EnvironmentName}.json", true, true) .AddEnvironmentVariables(); Configuration = builder.Build(); var siloHostBuilder = new SiloHostBuilder(); BsonClassMap.RegisterClassMap <AccountEvent>(cm => { cm.AutoMap(); cm.SetIsRootClass(true); }); BsonClassMap.RegisterClassMap <AccountNameEvent>(); BsonClassMap.RegisterClassMap <DepositEvent>(); BsonClassMap.RegisterClassMap <NewStakeholderEvent>(); BsonClassMap.RegisterClassMap <NewTransactionEvent>(); BsonClassMap.RegisterClassMap <WithdrawEvent>(); IMongoDatabase database; siloHostBuilder.Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "bancor-silohost"; }); switch (EnvironmentName) { case "Integration": siloHostBuilder .UseConsulClustering(options => { options.Address = new Uri("http://consul:8500"); }) .ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000); database = new MongoDbFactory().Create(); break; case "Development": siloHostBuilder .UseLocalhostClustering() .Configure <EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback); database = new MongoDbFactory().Create("mongodb://localhost:27017"); break; default: throw new Exception($"Unknown environment '{EnvironmentName}'"); } siloHostBuilder.Configure <ClusterOptions>(options => { options.ClusterId = "dev"; options.ServiceId = "bancor"; }) .ConfigureServices(s => s.TryAddSingleton <IGrainStorage, MongoCustomerStorageProvider>()) .ConfigureServices(s => s.TryAddTransient <ICustomerRepository, CustomerRepository>()) .ConfigureServices(s => s.TryAddSingleton(database)) .ConfigureServices(s => s.TryAddTransient <IJournaldAccountRepository, JournalAccountRepository>()) .ConfigureServices(s => s.AddSingletonNamedService <IGrainStorage>("CustomerStorageProvider", (x, y) => new MongoCustomerStorageProvider(database, (IGrainFactory)x.GetService(typeof(IGrainFactory))))) .ConfigureLogging(logging => logging.AddConsole()) .AddMemoryGrainStorageAsDefault() .AddSimpleMessageStreamProvider("SMSProvider") .AddMemoryGrainStorage("PubSubStore") .AddCustomStorageBasedLogConsistencyProvider("CustomStorage") .UseTransactions(); var host = siloHostBuilder.Build(); return(host); }