Antanidoss.Specification.Filters
1.1.0
dotnet add package Antanidoss.Specification.Filters --version 1.1.0
NuGet\Install-Package Antanidoss.Specification.Filters -Version 1.1.0
<PackageReference Include="Antanidoss.Specification.Filters" Version="1.1.0" />
paket add Antanidoss.Specification.Filters --version 1.1.0
#r "nuget: Antanidoss.Specification.Filters, 1.1.0"
// Install Antanidoss.Specification.Filters as a Cake Addin
#addin nuget:?package=Antanidoss.Specification.Filters&version=1.1.0
// Install Antanidoss.Specification.Filters as a Cake Tool
#tool nuget:?package=Antanidoss.Specification.Filters&version=1.1.0
Give a Star! ⭐
If you like or are using this project please give it a star. Thanks!
Usage
This project is intended to facilitate filtering in the repository. Usually, the problem of repositories is that they contain a large number of methods for different filtering. Now, it will be shown how to solve this problem with the help of this project.
To use this project, you need to familiarize yourself with https://github.com/Antanidoss/Antanidoss.Specification
And so, for example, we have such a class:
public interface IPersonRepository
{
IEnumerable<Person> GetFilter(ISpecification<Person> specification);
}
public class PersonRepository : IPersonRepository
{
private readonly EFDbContext _context;
public PersonRepository(EFDbContext context)
{
_context = context;
}
public IEnumerable<Person> GetBySpecification(ISpecification<Person> specification)
{
return _context.Persons.Where(specification.ToExpression());
}
}
The main disadvantage of this repository is that we will have to create many methods for different filtering. Let's pass this repository like this:
public interface IPersonRepository
{
IEnumerable<Person> GetByFilter(IQueryableMultipleResultFilter<Person> filter);
Person GetByFilter(IQueryableSingleResultFilter<Person> filter);
}
public class PersonRepository : IPersonRepository
{
private readonly EFDbContext _context;
public PersonRepository(EFDbContext context)
{
_context = context;
}
public IEnumerable<Person> GetByFilter(IQueryableMultipleResultFilter<Person> filter)
{
return filter.ApplyFilter(specification.ToExpression()).ToList();
}
public Person GetByFilter(IQueryableSingleResultFilter<Person> filter)
{
return filter.ApplyFilter(specification.ToExpression());
}
}
Now we have two methods:
IQueryableMultipleResultFilter - filter for the result as a collection.
IQueryableMultipleResultFilter - filter for the result as a collection.
How to create and use a filter?
var personByNameSpec = new PersonByNameSpec("Anton");
var personByAgeSpec = new PersonByAgeSpec(22);
var filter = new Where<Person>(personByNameSpec).FirstOrDefault<Person>(personByAgeSpec);
var person = personRepository.GetByFilter(filter);
We can combine filters in many ways. List of filters currently:
- Where
- FirstOrDefault
- FirstOrDefaultAsync
- OrderBy
- Include
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Antanidoss.Specification (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.