Ejemplo n.º 1
0
        private static void SetStorage(ISiloBuilder silo)
        {
            if (OrleansConfig.MongoDB.Enable)
            {
                silo.AddMongoDBGrainStorageAsDefault(op =>
                {
                    op.Configure(ooop =>
                    {
                        ooop.DatabaseName                    = OrleansConfig.MongoDB.DatabaseName + "_defaultgrain";
                        ooop.CreateShardKeyForCosmos         = OrleansConfig.MongoDB.CreateShardKeyForCosmos;
                        ooop.ConfigureJsonSerializerSettings = settings =>
                        {
                            settings.NullValueHandling      = NullValueHandling.Include;
                            settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                            settings.DefaultValueHandling   = DefaultValueHandling.Populate;
                        };
                    });
                });

                silo.AddMongoDBGrainStorage(GrainStorageKey.MongoDBStore, op =>
                {
                    op.Configure(ooop =>
                    {
                        ooop.DatabaseName                    = OrleansConfig.MongoDB.DatabaseName + "_grain";
                        ooop.CreateShardKeyForCosmos         = OrleansConfig.MongoDB.CreateShardKeyForCosmos;
                        ooop.ConfigureJsonSerializerSettings = settings =>
                        {
                            settings.NullValueHandling      = NullValueHandling.Include;
                            settings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                            settings.DefaultValueHandling   = DefaultValueHandling.Populate;
                        };
                    });
                });
            }
            else
            {
                silo.AddMemoryGrainStorage(GrainStorageKey.MongoDBStore);
            }

            if (OrleansConfig.Redis.Enable)
            {
                silo.AddRedisGrainStorage(GrainStorageKey.RedisStore, optionsBuilder => optionsBuilder.Configure(options =>
                {
                    options.DataConnectionString = $"{OrleansConfig.Redis.HostName}:{OrleansConfig.Redis.Port}";
                    options.UseJson        = OrleansConfig.Redis.UseJson;
                    options.DatabaseNumber = OrleansConfig.Redis.DatabaseNumber;
                }));
            }
            else
            {
                silo.AddMemoryGrainStorage(GrainStorageKey.RedisStore);
            }
        }