diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Context/ConfigureEntryStateDelegate.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Context/ConfigureEntryStateDelegate.cs deleted file mode 100644 index 36fefda..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Context/ConfigureEntryStateDelegate.cs +++ /dev/null @@ -1,7 +0,0 @@ -using Microsoft.EntityFrameworkCore.ChangeTracking; - -namespace Orleans.Providers.EntityFramework -{ - public delegate void ConfigureEntryStateDelegate(EntityEntry entry) - where TGrainState : class; -} \ No newline at end of file diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Context/GrainStorageContext.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Context/GrainStorageContext.cs deleted file mode 100644 index 757537d..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Context/GrainStorageContext.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Threading; - -namespace Orleans.Providers.EntityFramework -{ - /// - /// An async local context to apply modifications to current behavior of write and clear operations. - /// - /// - public static class GrainStorageContext - where TEntity : class - { - // ReSharper disable once StaticMemberInGenericType - private static readonly AsyncLocal IsConfiguredLocal - = new AsyncLocal(); - - private static readonly AsyncLocal> - ConfigureStateDelegateLocal - = new AsyncLocal>(); - - internal static bool IsConfigured => IsConfiguredLocal.Value; - - internal static ConfigureEntryStateDelegate ConfigureStateDelegate - => ConfigureStateDelegateLocal.Value; - - /// - /// Configures the entry state. - /// Use it to modify what gets changed during the write operations. - /// - /// The delegate to be called before saving context's state. - public static void ConfigureEntryState(ConfigureEntryStateDelegate configureState) - { - ConfigureStateDelegateLocal.Value = configureState; - IsConfiguredLocal.Value = true; - } - - public static void Clear() - { - ConfigureStateDelegateLocal.Value = null; - IsConfiguredLocal.Value = false; - } - } -} \ No newline at end of file diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Conventions/GetCompoundKeyDelegate.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Conventions/GetCompoundKeyDelegate.cs deleted file mode 100644 index f2b2052..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Conventions/GetCompoundKeyDelegate.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; -using Orleans.Runtime; - -namespace Orleans.Providers.EntityFramework.Conventions -{ - public delegate ValueType GetCompoundKeyDelegate(IAddressable addressable, out string keyExt); -} \ No newline at end of file diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Exceptions/GrainStorageConfigurationException.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Exceptions/GrainStorageConfigurationException.cs index 58faade..b32f80e 100644 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Exceptions/GrainStorageConfigurationException.cs +++ b/src/Pole.Orleans.Provider.EntityframeworkCore/Exceptions/GrainStorageConfigurationException.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; +using System.Text; -namespace Orleans.Providers.EntityFramework.Exceptions +namespace Pole.Orleans.Provider.EntityframeworkCore { // todo: Use for configuration errors public class GrainStorageConfigurationException : Exception @@ -17,4 +19,4 @@ namespace Orleans.Providers.EntityFramework.Exceptions { } } -} \ No newline at end of file +} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageOptionsExtensions.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageOptionsExtensions.cs index 245d05f..b7ea6fd 100644 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageOptionsExtensions.cs +++ b/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageOptionsExtensions.cs @@ -1,18 +1,19 @@ -using System; +using Microsoft.EntityFrameworkCore; +using Orleans.Runtime; +using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Text; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Orleans.Runtime; -using Pole.Orleans.Provider.EntityframeworkCore; -namespace Orleans.Providers.EntityFramework.Extensions +namespace Pole.Orleans.Provider.EntityframeworkCore { public static class GrainStorageOptionsExtensions { public static GrainStorageOptions UseQuery( this GrainStorageOptions options, - Func> queryFunc) + Func>queryFunc) where TContext : DbContext where TGrainState : class { @@ -258,4 +259,4 @@ namespace Orleans.Providers.EntityFramework.Extensions return options; } } -} \ No newline at end of file +} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageServiceCollectionExtensions.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageServiceCollectionExtensions.cs index c8d0d6a..ed16723 100644 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageServiceCollectionExtensions.cs +++ b/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageServiceCollectionExtensions.cs @@ -1,15 +1,17 @@ -using System; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; -using Orleans.Providers.EntityFramework.Conventions; +using Orleans; +using Orleans.Providers; using Orleans.Runtime; using Orleans.Storage; -using Pole.Orleans.Provider.EntityframeworkCore; using Pole.Orleans.Provider.EntityframeworkCore.Conventions; +using System; +using System.Collections.Generic; +using System.Text; -namespace Orleans.Providers.EntityFramework.Extensions +namespace Pole.Orleans.Provider.EntityframeworkCore { public static class GrainStorageServiceCollectionExtensions { @@ -67,4 +69,4 @@ namespace Orleans.Providers.EntityFramework.Extensions } } -} \ No newline at end of file +} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageSiloHostBuilderExtensions.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageSiloHostBuilderExtensions.cs index d5935f3..d1c195a 100644 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageSiloHostBuilderExtensions.cs +++ b/src/Pole.Orleans.Provider.EntityframeworkCore/Extensions/GrainStorageSiloHostBuilderExtensions.cs @@ -1,7 +1,11 @@ using Microsoft.EntityFrameworkCore; using Orleans.Hosting; +using Orleans.Providers; +using System; +using System.Collections.Generic; +using System.Text; -namespace Orleans.Providers.EntityFramework.Extensions +namespace Pole.Orleans.Provider.EntityframeworkCore { public static class GrainStorageSiloHostBuilderExtensions { @@ -15,15 +19,12 @@ namespace Orleans.Providers.EntityFramework.Extensions string providerName) where TContext : DbContext { - return builder - .ConfigureServices(services => - { - services.AddEfGrainStorage(providerName); - }); + .ConfigureServices(services => { services.AddEfGrainStorage(providerName); }); } + public static ISiloBuilder AddEfGrainStorageAsDefault(this ISiloBuilder builder) - where TContext : DbContext + where TContext : DbContext { return builder.AddEfGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME); } @@ -36,4 +37,4 @@ namespace Orleans.Providers.EntityFramework.Extensions .ConfigureServices(services => { services.AddEfGrainStorage(providerName); }); } } -} \ No newline at end of file +} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageConfigurationException.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageConfigurationException.cs deleted file mode 100644 index b32f80e..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageConfigurationException.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Pole.Orleans.Provider.EntityframeworkCore -{ - // todo: Use for configuration errors - public class GrainStorageConfigurationException : Exception - { - public GrainStorageConfigurationException() - { - } - - public GrainStorageConfigurationException(string message) : base(message) - { - } - - public GrainStorageConfigurationException(string message, Exception innerException) : base(message, innerException) - { - } - } -} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageOptionsExtensions.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageOptionsExtensions.cs deleted file mode 100644 index b7ea6fd..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageOptionsExtensions.cs +++ /dev/null @@ -1,262 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Orleans.Runtime; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; - -namespace Pole.Orleans.Provider.EntityframeworkCore -{ - public static class GrainStorageOptionsExtensions - { - public static GrainStorageOptions UseQuery( - this GrainStorageOptions options, - Func>queryFunc) - where TContext : DbContext - where TGrainState : class - { - options.DbSetAccessor = queryFunc; - return options; - } - - public static GrainStorageOptions ConfigureIsPersisted( - this GrainStorageOptions options, - Func isPersistedFunc) - where TContext : DbContext - where TGrainState : class - { - options.IsPersistedFunc = isPersistedFunc; - return options; - } - - /// - /// Instructs the storage provider to precompile read query. - /// This will lead to better performance for complex queries. - /// Default is to precompile. - /// - /// - /// - /// - /// - /// - /// - public static GrainStorageOptions PreCompileReadQuery( - this GrainStorageOptions options, - bool value = true) - where TContext : DbContext - where TGrainState : class - { - options.PreCompileReadQuery = value; - return options; - } - - - /// - /// Overrides the default implementation used to query grain state from database. - /// - /// - /// - /// - /// - /// - /// - public static GrainStorageOptions ConfigureReadState( - this GrainStorageOptions options, - Func> readStateAsyncFunc) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - - options.ReadStateAsync = readStateAsyncFunc ?? throw new ArgumentNullException(nameof(readStateAsyncFunc)); - return options; - } - - - /// - /// Instruct the storage that the current entity should use etags. - /// If no valid properties were found on the entity and exception would be thrown. - /// - /// - /// - /// - /// - /// - public static GrainStorageOptions UseETag( - this GrainStorageOptions options) - where TContext : DbContext - where TGrainState : class - { - options.ShouldUseETag = true; - return options; - } - - public static GrainStorageOptions UseETag( - this GrainStorageOptions options, - Expression> expression) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (expression == null) throw new ArgumentNullException(nameof(expression)); - - var memberExpression = expression.Body as MemberExpression - ?? throw new ArgumentException( - $"{nameof(expression)} must be a MemberExpression."); - - options.ETagPropertyName = memberExpression.Member.Name; - options.ShouldUseETag = true; - - return options; - } - - public static GrainStorageOptions UseETag( - this GrainStorageOptions options, - string propertyName) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - - options.ETagPropertyName = propertyName; - options.ShouldUseETag = true; - - return options; - } - - public static GrainStorageOptions UseKey( - this GrainStorageOptions options, - Expression> expression) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (expression == null) throw new ArgumentNullException(nameof(expression)); - - var memberExpression = expression.Body as MemberExpression - ?? throw new ArgumentException( - $"{nameof(expression)} must be a MemberExpression."); - - options.KeyPropertyName = memberExpression.Member.Name; - - return options; - } - - public static GrainStorageOptions UseKey( - this GrainStorageOptions options, - Expression> expression) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (expression == null) throw new ArgumentNullException(nameof(expression)); - - var memberExpression = expression.Body as MemberExpression - ?? throw new GrainStorageConfigurationException( - $"{nameof(expression)} must be a MemberExpression."); - - options.KeyPropertyName = memberExpression.Member.Name; - - return options; - } - - public static GrainStorageOptions UseKey( - this GrainStorageOptions options, - Expression> expression) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (expression == null) throw new ArgumentNullException(nameof(expression)); - - var memberExpression = expression.Body as MemberExpression - ?? throw new ArgumentException( - $"{nameof(expression)} must be a MemberExpression."); - - options.KeyPropertyName = memberExpression.Member.Name; - - return options; - } - - public static GrainStorageOptions UseKey( - this GrainStorageOptions options, - string propertyName) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - - options.KeyPropertyName = propertyName; - - return options; - } - - public static GrainStorageOptions UseKeyExt( - this GrainStorageOptions options, - Expression> expression) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (expression == null) throw new ArgumentNullException(nameof(expression)); - - var memberExpression = expression.Body as MemberExpression - ?? throw new ArgumentException( - $"{nameof(expression)} must be a MemberExpression."); - - options.KeyExtPropertyName = memberExpression.Member.Name; - - return options; - } - - public static GrainStorageOptions UseKeyExt( - this GrainStorageOptions options, - string propertyName) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - - options.KeyExtPropertyName = propertyName; - - return options; - } - - public static GrainStorageOptions CheckPersistenceOn( - this GrainStorageOptions options, - Expression> expression) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (expression == null) throw new ArgumentNullException(nameof(expression)); - - var memberExpression = expression.Body as MemberExpression - ?? throw new ArgumentException( - $"{nameof(expression)} must be a MemberExpression."); - - options.PersistenceCheckPropertyName = memberExpression.Member.Name; - - return options; - } - - public static GrainStorageOptions CheckPersistenceOn( - this GrainStorageOptions options, - string propertyName) - where TContext : DbContext - where TGrainState : class - { - if (options == null) throw new ArgumentNullException(nameof(options)); - if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - - options.PersistenceCheckPropertyName = propertyName; - - return options; - } - } -} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageServiceCollectionExtensions.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageServiceCollectionExtensions.cs deleted file mode 100644 index ed16723..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageServiceCollectionExtensions.cs +++ /dev/null @@ -1,72 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; -using Orleans; -using Orleans.Providers; -using Orleans.Runtime; -using Orleans.Storage; -using Pole.Orleans.Provider.EntityframeworkCore.Conventions; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Pole.Orleans.Provider.EntityframeworkCore -{ - public static class GrainStorageServiceCollectionExtensions - { - public static IServiceCollection ConfigureGrainStorageOptions( - this IServiceCollection services, - Action> configureOptions = null) - where TContext : DbContext - where TGrain : Grain - where TEntity : class, new() - { - return services - .AddSingleton>, - GrainStoragePostConfigureOptions>() - .Configure>(typeof(TGrain).FullName, options => - { - configureOptions?.Invoke(options); - }); - } - - public static IServiceCollection ConfigureGrainStorageOptions( - this IServiceCollection services, - Action> configureOptions = null) - where TContext : DbContext - where TGrain : Grain - where TGrainState : new() - where TEntity : class - { - return services - .AddSingleton>, - GrainStoragePostConfigureOptions>() - .Configure>(typeof(TGrain).FullName, options => - { - configureOptions?.Invoke(options); - }); - } - - public static IServiceCollection AddEfGrainStorage( - this IServiceCollection services, - string providerName = ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME) - where TContext : DbContext - { - services.TryAddSingleton(typeof(IEntityTypeResolver), typeof(EntityTypeResolver)); - services.TryAddSingleton(typeof(IGrainStorageConvention), typeof(GrainStorageConvention)); - services.TryAddSingleton(typeof(IGrainStateEntryConfigurator<,,>), - typeof(DefaultGrainStateEntryConfigurator<,,>)); - services.AddSingleton(typeof(EntityFrameworkGrainStorage)); - - services.TryAddSingleton(sp => - sp.GetServiceByName(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME)); - - services.AddSingletonNamedService(providerName, - (sp, name) => sp.GetRequiredService>()); - - return services; - } - - } -} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageSiloHostBuilderExtensions.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageSiloHostBuilderExtensions.cs deleted file mode 100644 index d1c195a..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/GrainStorageSiloHostBuilderExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Orleans.Hosting; -using Orleans.Providers; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Pole.Orleans.Provider.EntityframeworkCore -{ - public static class GrainStorageSiloHostBuilderExtensions - { - public static ISiloHostBuilder AddEfGrainStorageAsDefault(this ISiloHostBuilder builder) - where TContext : DbContext - { - return builder.AddEfGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME); - } - - public static ISiloHostBuilder AddEfGrainStorage(this ISiloHostBuilder builder, - string providerName) - where TContext : DbContext - { - return builder - .ConfigureServices(services => { services.AddEfGrainStorage(providerName); }); - } - - public static ISiloBuilder AddEfGrainStorageAsDefault(this ISiloBuilder builder) - where TContext : DbContext - { - return builder.AddEfGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME); - } - - public static ISiloBuilder AddEfGrainStorage(this ISiloBuilder builder, - string providerName) - where TContext : DbContext - { - return builder - .ConfigureServices(services => { services.AddEfGrainStorage(providerName); }); - } - } -} diff --git a/src/Pole.Orleans.Provider.EntityframeworkCore/ReadWriteStateAsyncDelegate.cs b/src/Pole.Orleans.Provider.EntityframeworkCore/ReadWriteStateAsyncDelegate.cs deleted file mode 100644 index e816f00..0000000 --- a/src/Pole.Orleans.Provider.EntityframeworkCore/ReadWriteStateAsyncDelegate.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Threading.Tasks; -using Orleans.Runtime; - -namespace Orleans.Providers.EntityFramework -{ - internal delegate Task ReadWriteStateAsyncDelegate(string grainType, GrainReference grainReference, - IGrainState grainState, object storageOptions); -} \ No newline at end of file