From f5fd28d4130df570afe5ecd3c83b60efabb58839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 26 Oct 2017 15:17:50 +0300 Subject: [PATCH] Created DataFilterOptions. --- src/Volo.Abp/Volo/Abp/Data/DataFilter.cs | 12 ++++++++---- src/Volo.Abp/Volo/Abp/Data/DataFilterItem.cs | 7 ------- src/Volo.Abp/Volo/Abp/Data/DataFilterOptions.cs | 15 +++++++++++++++ src/Volo.Abp/Volo/Abp/Data/DataFilterState.cs | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 11 deletions(-) delete mode 100644 src/Volo.Abp/Volo/Abp/Data/DataFilterItem.cs create mode 100644 src/Volo.Abp/Volo/Abp/Data/DataFilterOptions.cs create mode 100644 src/Volo.Abp/Volo/Abp/Data/DataFilterState.cs diff --git a/src/Volo.Abp/Volo/Abp/Data/DataFilter.cs b/src/Volo.Abp/Volo/Abp/Data/DataFilter.cs index c45b13a375..d4627d2683 100644 --- a/src/Volo.Abp/Volo/Abp/Data/DataFilter.cs +++ b/src/Volo.Abp/Volo/Abp/Data/DataFilter.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; namespace Volo.Abp.Data @@ -59,11 +60,14 @@ namespace Volo.Abp.Data } } - private readonly AsyncLocal _filter; + private readonly DataFilterOptions _options; - public DataFilter() + private readonly AsyncLocal _filter; + + public DataFilter(IOptions options) { - _filter = new AsyncLocal(); + _options = options.Value; + _filter = new AsyncLocal(); } public IDisposable Enable() @@ -97,7 +101,7 @@ namespace Volo.Abp.Data return; } - _filter.Value = new DataFilterItem { IsEnabled = true }; //TODO: Get from default setting! + _filter.Value = _options.DefaultStates.GetOrDefault(typeof(TFilter))?.Clone() ?? new DataFilterState(true); } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Data/DataFilterItem.cs b/src/Volo.Abp/Volo/Abp/Data/DataFilterItem.cs deleted file mode 100644 index 94d7cc8ac7..0000000000 --- a/src/Volo.Abp/Volo/Abp/Data/DataFilterItem.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.Data -{ - internal class DataFilterItem - { - public bool IsEnabled { get; set; } - } -} \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Data/DataFilterOptions.cs b/src/Volo.Abp/Volo/Abp/Data/DataFilterOptions.cs new file mode 100644 index 0000000000..dbf5187c73 --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/Data/DataFilterOptions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.Data +{ + public class DataFilterOptions + { + public Dictionary DefaultStates { get; } + + public DataFilterOptions() + { + DefaultStates = new Dictionary(); + } + } +} diff --git a/src/Volo.Abp/Volo/Abp/Data/DataFilterState.cs b/src/Volo.Abp/Volo/Abp/Data/DataFilterState.cs new file mode 100644 index 0000000000..fe66f5d0d1 --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/Data/DataFilterState.cs @@ -0,0 +1,17 @@ +namespace Volo.Abp.Data +{ + public class DataFilterState + { + public bool IsEnabled { get; set; } + + public DataFilterState(bool isEnabled) + { + IsEnabled = isEnabled; + } + + public DataFilterState Clone() + { + return new DataFilterState(IsEnabled); + } + } +} \ No newline at end of file