diff --git a/Orleans.Persistence.Redis.E2E/Orleans.Persistence.Redis.E2E.csproj b/Orleans.Persistence.Redis.E2E/Orleans.Persistence.Redis.E2E.csproj index e561441..874129b 100644 --- a/Orleans.Persistence.Redis.E2E/Orleans.Persistence.Redis.E2E.csproj +++ b/Orleans.Persistence.Redis.E2E/Orleans.Persistence.Redis.E2E.csproj @@ -7,14 +7,14 @@ - - + + all runtime; build; native; contentfiles; analyzers - - - + + + diff --git a/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs b/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs index 7114c01..0f090c0 100644 --- a/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs +++ b/Orleans.Persistence.Redis/Config/RedisSiloHostBuilderExtensions.cs @@ -29,7 +29,7 @@ string name public static RedisStorageOptionsBuilder AddRedisGrainStorageAsDefault( this ISiloBuilder builder ) => builder.AddRedisGrainStorage("Default"); - + internal static IServiceCollection AddRedisGrainStorage( this IServiceCollection services, string name, @@ -38,16 +38,16 @@ internal static IServiceCollection AddRedisGrainStorage( { configureOptions?.Invoke(services.AddOptions(name)); // services.AddTransient(sp => new DynamoDBGrainStorageOptionsValidator(sp.GetService>().Get(name), name)); - services.AddSingletonNamedService(name, CreateStateStore); + services.AddKeyedSingleton(name, CreateStateStore); services.ConfigureNamedOptionForLogging(name); services.TryAddSingleton(sp => - sp.GetServiceByName(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME)); + sp.GetKeyedService(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME)); return services - .AddSingletonNamedService(name, CreateDbConnection) - .AddSingletonNamedService(name, CreateRedisStorage) - .AddSingletonNamedService(name, (provider, n) - => (ILifecycleParticipant)provider.GetRequiredServiceByName(n)); + .AddKeyedSingleton(name, CreateDbConnection) + .AddKeyedSingleton(name, CreateRedisStorage) + .AddKeyedSingleton(name, (provider, n) + => (ILifecycleParticipant)provider.GetRequiredKeyedService(n)); } internal static ISiloBuilder AddRedisDefaultSerializer(this ISiloBuilder builder, string name) @@ -55,7 +55,7 @@ internal static ISiloBuilder AddRedisDefaultSerializer(this ISiloBuilder builder internal static ISiloBuilder AddRedisDefaultBrotliSerializer(this ISiloBuilder builder, string name) => builder.AddRedisSerializer(name); - + internal static ISiloBuilder AddRedisDefaultHumanReadableSerializer(this ISiloBuilder builder, string name) => builder.AddRedisHumanReadableSerializer( name, @@ -65,7 +65,7 @@ internal static ISiloBuilder AddRedisDefaultHumanReadableSerializer(this ISiloBu internal static ISiloBuilder AddCompression(this ISiloBuilder builder, string name) where TCompression : ICompression => builder.ConfigureServices(services => - services.AddSingletonNamedService(name, (provider, n) + services.AddKeyedSingleton(name, (provider, n) => ActivatorUtilities.CreateInstance(provider))); internal static ISiloBuilder AddRedisSerializer( @@ -75,7 +75,7 @@ params object[] settings ) where TSerializer : ISerializer => builder.ConfigureServices(services => - services.AddSingletonNamedService(name, (provider, n) + services.AddKeyedSingleton(name, (provider, n) => ActivatorUtilities.CreateInstance(provider, settings)) ); @@ -86,7 +86,7 @@ params object[] settings ) where TSerializer : IHumanReadableSerializer => builder.ConfigureServices(services => - services.AddSingletonNamedService(name, (provider, n) + services.AddKeyedSingleton(name, (provider, n) => ActivatorUtilities.CreateInstance(provider, settings)) ); @@ -96,24 +96,24 @@ internal static ISiloBuilder AddRedisHumanReadableSerializer( Func cfg ) where TSerializer : IHumanReadableSerializer => builder.ConfigureServices(services => - services.AddSingletonNamedService(name, (provider, n) + services.AddKeyedSingleton(name, (provider, n) => ActivatorUtilities.CreateInstance(provider, cfg?.Invoke(provider))) ); - + private static IGrainStorage CreateRedisStorage(IServiceProvider services, string name) { - var store = services.GetRequiredServiceByName(name); - var connection = services.GetRequiredServiceByName(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.GetRequiredServiceByName(name); - var serializer = provider.GetRequiredServiceByName(name); - var humanReadableSerializer = provider.GetServiceByName(name); - var options = provider.GetRequiredService>(); - var logger = provider.GetRequiredService>(); + 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, diff --git a/Orleans.Persistence.Redis/Core/GrainStateStore.cs b/Orleans.Persistence.Redis/Core/GrainStateStore.cs index 9c9c4b8..f3532eb 100644 --- a/Orleans.Persistence.Redis/Core/GrainStateStore.cs +++ b/Orleans.Persistence.Redis/Core/GrainStateStore.cs @@ -1,10 +1,10 @@ using ByteSizeLib; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Orleans.Persistence.Redis.Compression; 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; @@ -41,7 +41,7 @@ IServiceProvider services _humanReadableSerializer = humanReadableSerializer; _logger = logger; _options = options; - _compression = services.GetServiceByName(name); + _compression = services.GetKeyedService(name); } public async Task> GetGrainState(string grainId, Type stateType) diff --git a/Orleans.Persistence.Redis/Orleans.Persistence.Redis.csproj b/Orleans.Persistence.Redis/Orleans.Persistence.Redis.csproj index 24e4d34..a480ca6 100644 --- a/Orleans.Persistence.Redis/Orleans.Persistence.Redis.csproj +++ b/Orleans.Persistence.Redis/Orleans.Persistence.Redis.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/Samples/TestClient/TestClient.csproj b/Samples/TestClient/TestClient.csproj index 5599128..06db793 100644 --- a/Samples/TestClient/TestClient.csproj +++ b/Samples/TestClient/TestClient.csproj @@ -8,7 +8,7 @@ - + diff --git a/Samples/TestGrains/TestGrains.csproj b/Samples/TestGrains/TestGrains.csproj index 6d6e072..1ddb074 100644 --- a/Samples/TestGrains/TestGrains.csproj +++ b/Samples/TestGrains/TestGrains.csproj @@ -6,7 +6,7 @@ - + diff --git a/Samples/TestSilo/TestSilo.csproj b/Samples/TestSilo/TestSilo.csproj index ec9bb90..0171361 100644 --- a/Samples/TestSilo/TestSilo.csproj +++ b/Samples/TestSilo/TestSilo.csproj @@ -8,7 +8,7 @@ - +