Skip to content

Commit

Permalink
feat(state store): refactor di activator (#26)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Sant <jonathan.sant@live.co.uk>
  • Loading branch information
jonathansant committed Feb 2, 2024
1 parent e8e33b8 commit 74cb268
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
33 changes: 13 additions & 20 deletions Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,23 @@ private static IGrainStorage CreateRedisStorage(IServiceProvider services, strin
return ActivatorUtilities.CreateInstance<RedisGrainStorage>(services, name, store, connection);
}

private static IGrainStateStore CreateStateStore(IServiceProvider provider, string name)
{
var connection = provider.GetRequiredServiceByName<DbConnection>(name);
var serializer = provider.GetRequiredServiceByName<ISerializer>(name);
var humanReadableSerializer = provider.GetServiceByName<IHumanReadableSerializer>(name);
var options = provider.GetRequiredService<IOptionsSnapshot<RedisStorageOptions>>();
var compress = provider.GetServiceByName<ICompression>(name);

if (compress != null)
return ActivatorUtilities.CreateInstance<GrainStateStore>(
provider,
private static IGrainStateStore CreateStateStore(IServiceProvider provider, string name)
{
var connection = provider.GetRequiredServiceByName<DbConnection>(name);
var serializer = provider.GetRequiredServiceByName<ISerializer>(name);
var humanReadableSerializer = provider.GetServiceByName<IHumanReadableSerializer>(name);
var options = provider.GetRequiredService<IOptionsSnapshot<RedisStorageOptions>>();
var logger = provider.GetRequiredService<ILogger<GrainStateStore>>();

return ActivatorUtilities.CreateInstance<GrainStateStore>(
provider,
name,
connection,
options.Get(name),
serializer,
humanReadableSerializer,
compress
);

return ActivatorUtilities.CreateInstance<GrainStateStore>(
provider,
connection,
options.Get(name),
serializer,
humanReadableSerializer
logger,
provider
);
}

Expand Down
16 changes: 4 additions & 12 deletions Orleans.Persistence.Redis/Core/GrainStateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,30 +31,21 @@ internal class GrainStateStore : IGrainStateStore
private readonly ICompression _compression;

public GrainStateStore(
DbConnection connection,
RedisStorageOptions options,
ISerializer serializer,
IHumanReadableSerializer humanReadableSerializer,
ILogger<GrainStateStore> logger
) : this(connection, options, serializer, humanReadableSerializer, logger, null)
{
}

public GrainStateStore(
string name,
DbConnection connection,
RedisStorageOptions options,
ISerializer serializer,
IHumanReadableSerializer humanReadableSerializer,
ILogger<GrainStateStore> logger,
ICompression compression
IServiceProvider services
)
{
_connection = connection;
_serializer = serializer;
_humanReadableSerializer = humanReadableSerializer;
_logger = logger;
_options = options;
_compression = compression;
_compression = services.GetServiceByName<ICompression>(name);
}

public async Task<IGrainState<T>> GetGrainState<T>(string grainId, Type stateType)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand Down

0 comments on commit 74cb268

Please sign in to comment.