mardi 24 février 2015

How to use "Composite Design Pattern" with Ninject

Validation Rule Contract:



public interface IValidationRule
{
bool IsValid();
}


Concrete Validation Rule:



public class MyClass : IValidationRule
{
public bool IsValid()
{
return true;
}
}


Composite:



public class ValidationRuleComposite : IValidationRule
{
private readonly IEnumerable<IValidationRule> _validationRules;

public ValidationRuleComposite(IEnumerable<IValidationRule> validationRules)
{
_validationRules = validationRules;
}

public bool IsValid()
{
return _validationRules.All(x => x.IsValid());
}
}


When I ask the containter for IValidationRule I want to get ValidationRuleComposite. If I ask the container for a list of IValidationRule I want to get all implementations of IValidationRule except of the ValidationRuleComposite.


How can I achieve this with Ninject?


Aucun commentaire:

Enregistrer un commentaire