diff --git a/CHANGELOG.md b/CHANGELOG.md index ab5bcff..0b4e0e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -## [3.0.0](https://github.com/jonathansant/orleans.persistence.redis/compare/2.2.0...3.0.0) (2024-02-06) +## [3.0.1](https://github.com/jonathansant/orleans.persistence.redis/compare/2.2.0...3.0.0) (2024-02-14) + +### Bug Fixes + +- fix configuration + +## [3.0.0](https://github.com/jonathansant/orleans.persistence.redis/compare/2.2.0...3.0.0) (2024-02-06) ### Features diff --git a/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs b/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs index 0f090c0..047706a 100644 --- a/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs +++ b/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs @@ -1,5 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; +#nullable enable +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; @@ -9,8 +9,7 @@ using Orleans.Persistence.Redis.Config; using Orleans.Persistence.Redis.Core; using Orleans.Persistence.Redis.Serialization; -using Orleans.Providers; -using Orleans.Runtime; +using Orleans.Runtime.Hosting; using Orleans.Serialization; using Orleans.Storage; using JsonSerializer = Orleans.Persistence.Redis.Serialization.JsonSerializer; @@ -21,10 +20,8 @@ namespace Orleans.Hosting; public static class RedisSiloBuilderExtensions { - public static RedisStorageOptionsBuilder AddRedisGrainStorage( - this ISiloBuilder builder, - string name - ) => new RedisStorageOptionsBuilder(builder, name); + public static RedisStorageOptionsBuilder AddRedisGrainStorage(this ISiloBuilder builder, string name) + => new(builder, name); public static RedisStorageOptionsBuilder AddRedisGrainStorageAsDefault( this ISiloBuilder builder @@ -33,21 +30,59 @@ this ISiloBuilder builder internal static IServiceCollection AddRedisGrainStorage( this IServiceCollection services, string name, - Action> configureOptions = null + Action>? configureOptions = null ) { configureOptions?.Invoke(services.AddOptions(name)); - // services.AddTransient(sp => new DynamoDBGrainStorageOptionsValidator(sp.GetService>().Get(name), name)); - services.AddKeyedSingleton(name, CreateStateStore); services.ConfigureNamedOptionForLogging(name); - services.TryAddSingleton(sp => - sp.GetKeyedService(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME)); + // services.AddTransient(sp => new DynamoDBGrainStorageOptionsValidator(sp.GetService>().Get(name), name)); return services - .AddKeyedSingleton(name, CreateDbConnection) - .AddKeyedSingleton(name, CreateRedisStorage) - .AddKeyedSingleton(name, (provider, n) - => (ILifecycleParticipant)provider.GetRequiredKeyedService(n)); + .AddKeyedSingleton(name, (sp, k) => + { + var key = (string)k; + var connection = sp.GetRequiredKeyedService(key); + var serializer = sp.GetRequiredKeyedService(key); + var humanReadableSerializer = sp.GetKeyedService(key); + var options = sp.GetRequiredService>(); + var logger = sp.GetRequiredService>(); + + return ActivatorUtilities.CreateInstance( + sp, + key, + connection, + options.Get(key), + serializer, + humanReadableSerializer, + logger, + sp + ); + } + ) + .AddKeyedSingleton(name, (sp, k) => + { + var key = (string)k; + var optionsSnapshot = sp.GetRequiredService>(); + var logger = sp.GetRequiredService>(); + return ActivatorUtilities.CreateInstance(sp, optionsSnapshot.Get(key), logger); + } + ) + .AddKeyedSingleton(name, (sp, k) => + { + var key = (string)k; + var store = sp.GetRequiredKeyedService(key); + var connection = sp.GetRequiredKeyedService(key); + return ActivatorUtilities.CreateInstance(sp, key, store, connection); + } + ) + .AddGrainStorage(name, (sp, key) => + { + var store = sp.GetRequiredKeyedService(key); + var connection = sp.GetRequiredKeyedService(key); + return ActivatorUtilities.CreateInstance(sp, key, store, connection); + } + ) + ; } internal static ISiloBuilder AddRedisDefaultSerializer(this ISiloBuilder builder, string name) @@ -99,40 +134,6 @@ Func cfg services.AddKeyedSingleton(name, (provider, n) => ActivatorUtilities.CreateInstance(provider, cfg?.Invoke(provider))) ); - - private static IGrainStorage CreateRedisStorage(IServiceProvider services, string name) - { - var store = services.GetRequiredKeyedService(name); - var connection = services.GetRequiredKeyedService(name); - return ActivatorUtilities.CreateInstance(services, name, store, connection); - } - - private static IGrainStateStore CreateStateStore(IServiceProvider provider, string name) - { - var connection = provider.GetRequiredKeyedService(name); - var serializer = provider.GetRequiredKeyedService(name); - var humanReadableSerializer = provider.GetKeyedServices(name); - var options = provider.GetRequiredService>(); - var logger = provider.GetRequiredService>(); - - return ActivatorUtilities.CreateInstance( - provider, - name, - connection, - options.Get(name), - serializer, - humanReadableSerializer, - logger, - provider - ); - } - - private static DbConnection CreateDbConnection(IServiceProvider provider, string name) - { - var optionsSnapshot = provider.GetRequiredService>(); - var logger = provider.GetRequiredService>(); - return ActivatorUtilities.CreateInstance(provider, optionsSnapshot.Get(name), logger); - } } public static class RedisDefaultJsonSerializerSettings diff --git a/package.json b/package.json index 6c7bf4e..1317fdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sucrose.orleans.persistence.redis", - "version": "3.0.0", + "version": "3.0.1", "description": "Orleans Redis Persistence Provider", "solution": "Orleans.Persistence.Redis-build.sln", "dependencies": {},