Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend DataFilter implementation #7706

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

olicooper
Copy link
Contributor

@olicooper olicooper commented Feb 12, 2021

I would like to propose some updates to the DataFilter implementation. The changes should be non-breaking as the base functionality remains the same, with an additional IsActive attribute along with some additional useful methods.
I have made a number of changes but my main motivation is to know which filters are currently 'active' (being used within a disposable scope). Having access to information about the filters is also very useful.

Because DataFilter is ISingletonDependency the cached filters are kept in memory after their first use. The IsEnabled property isn't a reliable source because the default IsEnabled value can be changed per filter with AbpDataFilterOptions. I tried making the DataFilter Scoped; but the scope can change within a request so the filters reset.

I have added various tests to ensure these work within all common scenarios and I've added documentation to guide developers for the correct use of each method.

Initially, I intend to use this in conjunction with the abp-queryfilter-test project I am working on (mentioned here) - where you can the proposed changes in use.

Changes include:

  • Add new methods (GetOrAddFilter, IsActive) and add ReadOnlyFilters property to DataFilter
  • Make DataFilter extensible (virtual methods etc.)
  • Add ability to set the DefaultFilterState in AbpDataFilterOptions
  • Add test suite
  • Improve method XML descriptions

* Add new methods (GetOrAddFilter, IsActive) and add ReadOnlyFilters to DataFilter
* Make DataFilter extensible
* Add ability to set the DefaultFilterState in AbpDataFilterOptions
* Add test suite
* Improve method XML descriptions
@gterdem gterdem requested a review from hikalkan February 12, 2021 11:46
@gterdem gterdem added this to the backlog milestone Feb 12, 2021
@hikalkan
Copy link
Member

Thanks @olicooper for this PR.

Having access to information about the filters is also very useful.

Can you please give more info for the use cases? You can show some usage examples and explain the reason. I didn't understand how it is supposed to be used and what are the benefit of such an active concept.

@olicooper
Copy link
Contributor Author

Yeah sure I will try 😃. The reason I created this PR was partly to facilitate the a proposed change in how data filters are applied in ABP (I created a ticket on the issue here). But essentially, without IsActive you can't see which cached filters are applied for a given query due to the Singleton nature of DataFilters and you can't make DataFilters scoped because nested scopes are created within each request.

Official filters are ISoftDelete and IMultiTenant, but the filtering system allows for anything to be specified, for example I have also created IPassivable (filter for active entities) and ITemplatable (filter for entities marked as templates). The main reason for needing IsActive is to perform conditional logic based on the filter value from within a nested method call or query interceptor. One example could be when filtering for template records, I also require that I search for non-tenant records. But I think it is best to see it in action so here is a real example using the filters to determine if I should modify the EF query before sending it to the database. I didn't know which filters were active within the DbContext because the query is being intercepted rather than being directly called by the AppService, so without IsActive I wouldn't be able to modify the query accordingly.

See AbpFilterAppendingExpressionVisitor.cs - you can also check out the whole demo if you'd like 😀

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants