I have a interface (client) with multiples filters, per e.j:
- Search by Code
- Search by Name
- Search by Last Name
- Search by ....
In these cases, I look with always the need of create a new Criteria object, per e.j.:
- SearchByCodeCriteria
- SearchByNameCriteria
- SearchByLastNameCriteria
- SearchBy....
A form of solution maybe create a class with this filters:
public class Filters
{
string Code
string Name
string LastName
}
This class may put in the constructor of any Criteria Object. But the problem is the same, I need always of conditionals, p.e.:
If (!String.NullOrEmpty(Foo.Code))
Filters.Code = Foo.Code;
This same problem repeat been in the moment to fetch in the DataPortal:
If (!String.NullOrEmpty(Filters.Code))
data = targetRepository.FetchByCode(Filters.Code);
If (!String.NullOrEmpty(Filters.Name))
data = targetRepository.FetchByName(Filters.Name);
The questions is:
Exists any pattern for Criterias, similar to Specifications in DDD, I understand with CSLA .NET is not a ORM, but I think the conditionals in CSLA framework to Criterias Objects is a little problem.
Can you help me with any pattern?
P.D.: I use IoC and DI with Unity, also use Managed Extensibility Framework (MEF) with CSLA .NET to apply polymorphism, but my problem is when I need apply this concepts with the Criteria Objects.
Maybe an option:
public interface IDynamicList<T>
{
List<T> FindAllByCriteria(string criteria);
List<T> FindAllByCriteria(Func<T, bool> criteria);
}
[Export(typeof(ICustomerRepository))]
public class CustomerMock : ICustomerRepository
{
public List<Dto.CustomerDto> FindAllByCriteria(Func<Dto.CustomerDto, bool> criteria)
{
throw new NotImplementedException();
}
}
Best regards
Beyondnet
http://www.cslanet.org