Skip to content

Implement an infrastructure for auto discovery of evaluators and validators.#30

Merged
fiseni merged 11 commits into
mainfrom
fiseni/evaluator-discovery
Jun 7, 2025
Merged

Implement an infrastructure for auto discovery of evaluators and validators.#30
fiseni merged 11 commits into
mainfrom
fiseni/evaluator-discovery

Conversation

@fiseni

@fiseni fiseni commented Jun 5, 2025

Copy link
Copy Markdown
Owner

Added the ability to automatically discover the partial evaluators and validators. The users, once they add implementations for IEvaluator, IMemoryEvaluator, or IValidator, no longer need to add/register them manually. They will be discovered automatically and added to the pipeline.

I wanted to expose this as an optional feature. I added targets as part of the NuGet package, and the feature can be enabled by setting the following property in your .csproj file

<PropertyGroup>
  <SpecAutoDiscovery>enable</SpecAutoDiscovery>
</PropertyGroup>

Additionally, a discovery attribute can be applied to each evaluator/validator individually. You can control the order and also have the ability to disable a specific evaluator/validator from discovery. The default order is int.MaxValue and is enabled by default. If no attribute is applied, the default values will be assumed.

[EvaluatorDiscovery(Order = 1000, Enable = true)]
public class TestEvaluator : IEvaluator
{
    public IQueryable<T> Evaluate<T>(IQueryable<T> source, Specification<T> specification) where T : class
    {
        // Your implementation here
        return source;
    }
}

[EvaluatorDiscovery(Order = 1000, Enable = true)]
public class TestMemoryEvaluator : IMemoryEvaluator
{
    public IEnumerable<T> Evaluate<T>(IEnumerable<T> source, Specification<T> specification)
    {
        // Your implementation here
        return source;
    }
}

[ValidatorDiscovery(Order = 1000, Enable = true)]
public class TestValidator : IValidator
{
    public bool IsValid<T>(T entity, Specification<T> specification)
    {
        // Your implementation here
        return true;
    }
}

@fiseni fiseni requested a review from Copilot June 5, 2025 12:55

This comment was marked as resolved.

@fiseni fiseni marked this pull request as ready for review June 7, 2025 21:42
@fiseni fiseni requested a review from Copilot June 7, 2025 21:42

This comment was marked as resolved.

@fiseni fiseni merged commit e1a75eb into main Jun 7, 2025
1 check passed
@fiseni fiseni deleted the fiseni/evaluator-discovery branch June 7, 2025 21:55
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.

2 participants