🧠 Intelligent Context

Smart Validation System

EasyValidate's intelligent validation context system provides automatic dependency injection and type-safe access to current model instances. Build sophisticated validation logic with compile-time safety and analyzer enforcement.

4Examples
4Features

Smart Validation in Action

See how EasyValidate's intelligent context system provides automatic dependency injection and type-safe model access.

Automatic Service Provider Injection
EasyValidate automatically injects services into init properties of your validation attributes via the ValidationConfig.
Auto-InjectionInit PropertiesMultiple ServicesClean Architecture
ValidationContext for Current Instance
Access the current model instance using ValidationContext attribute with compile-time type checking.
ValidationContextCross-Property AccessBusiness LogicType Safety
Model with ValidationContext Attribute
Models must be partial classes implementing IGenerate to work with ValidationContext.
Partial ClassIGenerate InterfaceReal UsageDependency Injection
Complex Async Validation with Context
Use ValidationContext with async validation for sophisticated business rules.
Async + ContextRole-Based RulesComplex ValidationType Safety

Smart System Features

EasyValidate's intelligent features make building complex validation logic simple and type-safe.

Automatic Service Provider Detection
EasyValidate automatically detects and injects IServiceProvider properties in validation attributes.
Any Property NameZero ConfigurationRuntime InjectionService Resolution
Smart ValidationContext Injection
Access current model instances through ValidationContextAttribute with compile-time type enforcement.
Type SafetyInterface EnforcementAnalyzer SupportMultiple Contexts
Compile-Time Analyzer Enforcement
Analyzers ensure models implement all interfaces used in ValidationContext properties.
Compile-Time ErrorsInterface ValidationType CheckingDeveloper Guidance
Flexible Architecture
Combine service injection and context access for powerful validation scenarios.
Service + ContextBusiness LogicExternal ServicesComplex Scenarios

Analyzer Enforcement

EasyValidate analyzers enforce type safety and guide developers to correct implementations.

Missing IGenerate Interface
When a model doesn't implement IGenerate interface
// ❌ This will cause compiler error EASY001
public class Product  // Missing IGenerate!
{
    [NotNull]
    public string? Name { get; set; }
}

// ✅ Correct implementation
public partial class Product : IGenerate
{
    [NotNull]
    public string? Name { get; set; }
}

Analyzer Message:

EASY001: Model must implement IGenerate interface to use EasyValidate attributes

Missing Partial Keyword
When a model implementing IGenerate is not declared as partial
// ❌ This will cause compiler error EASY002
public class Product : IGenerate  // Missing partial!
{
    [NotNull]
    public string? Name { get; set; }
}

// ✅ Correct implementation
public partial class Product : IGenerate
{
    [NotNull]
    public string? Name { get; set; }
}

Analyzer Message:

EASY002: Class implementing IGenerate must be declared as partial