From ad8394dfcd5e51515990a5350e911a3bdecd7063 Mon Sep 17 00:00:00 2001 From: Clayton Lautier Date: Fri, 2 Feb 2024 10:25:02 +0100 Subject: [PATCH] feat(state store): refactor di activator (#26) Co-authored-by: Jonathan Sant --- .../Config/RedisSiloHostBuilderExtensions.cs | 33 ++++++++----------- .../Core/GrainStateStore.cs | 16 +++------ package.json | 2 +- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs b/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs index c335ee8..7114c01 100644 --- a/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs +++ b/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs @@ -107,30 +107,23 @@ private static IGrainStorage CreateRedisStorage(IServiceProvider services, strin return ActivatorUtilities.CreateInstance(services, name, store, connection); } - private static IGrainStateStore CreateStateStore(IServiceProvider provider, string name) - { - var connection = provider.GetRequiredServiceByName(name); - var serializer = provider.GetRequiredServiceByName(name); - var humanReadableSerializer = provider.GetServiceByName(name); - var options = provider.GetRequiredService>(); - var compress = provider.GetServiceByName(name); - - if (compress != null) - return ActivatorUtilities.CreateInstance( - provider, + private static IGrainStateStore CreateStateStore(IServiceProvider provider, string name) + { + var connection = provider.GetRequiredServiceByName(name); + var serializer = provider.GetRequiredServiceByName(name); + var humanReadableSerializer = provider.GetServiceByName(name); + var options = provider.GetRequiredService>(); + var logger = provider.GetRequiredService>(); + + return ActivatorUtilities.CreateInstance( + provider, + name, connection, options.Get(name), serializer, humanReadableSerializer, - compress - ); - - return ActivatorUtilities.CreateInstance( - provider, - connection, - options.Get(name), - serializer, - humanReadableSerializer + logger, + provider ); } diff --git a/Orleans.Persistence.Redis/Core/GrainStateStore.cs b/Orleans.Persistence.Redis/Core/GrainStateStore.cs index f2a1e86..9c9c4b8 100644 --- a/Orleans.Persistence.Redis/Core/GrainStateStore.cs +++ b/Orleans.Persistence.Redis/Core/GrainStateStore.cs @@ -4,6 +4,7 @@ using Orleans.Persistence.Redis.Config; using Orleans.Persistence.Redis.Serialization; using Orleans.Persistence.Redis.Utils; +using Orleans.Runtime; using Orleans.Storage; using StackExchange.Redis; using System.Text; @@ -26,22 +27,13 @@ internal class GrainStateStore : IGrainStateStore private readonly ICompression _compression; public GrainStateStore( - DbConnection connection, - RedisStorageOptions options, - ISerializer serializer, - IHumanReadableSerializer humanReadableSerializer, - ILogger logger - ) : this(connection, options, serializer, humanReadableSerializer, logger, null) - { - } - - public GrainStateStore( + string name, DbConnection connection, RedisStorageOptions options, ISerializer serializer, IHumanReadableSerializer humanReadableSerializer, ILogger logger, - ICompression compression + IServiceProvider services ) { _connection = connection; @@ -49,7 +41,7 @@ ICompression compression _humanReadableSerializer = humanReadableSerializer; _logger = logger; _options = options; - _compression = compression; + _compression = services.GetServiceByName(name); } public async Task> GetGrainState(string grainId, Type stateType) diff --git a/package.json b/package.json index 134dc31..19264b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sucrose.orleans.persistence.redis", - "version": "2.2.0", + "version": "2.2.1", "description": "Orleans Redis Persistence Provider", "solution": "Orleans.Persistence.Redis-build.sln", "dependencies": {},