Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:53:06+00:00 2026-05-26T07:53:06+00:00

I have a validation interface like so: public interface IValidation<T> { bool IsValid(T item,

  • 0

I have a validation interface like so:

public interface IValidation<T> {
  bool IsValid(T item, ref AggregateException fail);
}

I have a file importer that needs several validation interfaces

public FileImporter {
  IEnumerable<IValidation<Patient>> Validators { get; set; }

  public FileImporter(IWindsorContainer container) {
    // the ResolveAll method does not do this
    Validators = container.ResolveAll<IValidation<Patient>>("fileValidation");
  }
}

I also have another class that has more validators but uses some of the same ones used in FileImporter.

public PatientService {
  IEnumerable<IValidation<Patient>> Validators { get; set; }

  public PatientService(IWindsorContainer container) {
    // the ResolveAll method does not do this
    Validators = container.ResolveAll<IValidation<Patient>>("userInputValidation");
  }
}

For example I have two validators LastNameValidator and DateOfBirthValidator. LastNameValidator is used in both theFileImporterand thePatientService.DateOfBirthValidatoris only used in thePatientService` class. The implementation of these two classes are below the question.

My question is how can i wire up these two classes so that they are used as described above. And what method call should I make to resolve them?

public class LastNameValidator : IValidation<Patient> {
  public bool IsValid(Patient p, ref AggregateException fail) {
    var isValid = !string.IsNullOrWhitespace(p.LastName))
    if (!isValid)
        // update fail
    return isValid;
  }
}

public class DateOfBirthValidator : IValidation<Patient> {
  public bool IsValid(Patient p, ref AggregateException fail) {

    if (!p.DateOfBirth.HasValue) {
        // update fail, can't be empty
        return false;
    }
    if (p.DateOfBirth.Value > DateTime.Now) {
        // update fail, can't be in future
        return false;
    }
    return true;
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:53:07+00:00Added an answer on May 26, 2026 at 7:53 am

    I would consider the Typed Factory Facility. You could register your validators with the names “lastnamevalidator” and “dobvalidator”. Then create a factory interface for grabbing those specific validators. You just need the interface — the facility will do the implementation:

    public interface IValidatorFactory
    {
        IValidator GetLastNameValidator();
        IValidator GetDobValidator();
    }
    

    Now pass the IValidatorFactory to your component. This also removes the need to pass the Windsor container around (which isn’t a good idea as it tightly couples your code to Windsor and makes unit testing more difficult).

    Now just call the factory methods to access the particular validator each component needs.

    UPDATE:

    Still not clear on which part of your system is going to determine which IValidators to use, but maybe this would work. Use a marker inteface that is based on IValidator.

    public interface IFileValidator : IValidator
    {
    }
    
    public interface IUserInputValidator : IValidator
    {
    }
    

    Now have your validators implement the marker interfaces depending on where they are going to be used — and remember you can implement multiple interfaces so validators can be used in multiple situations. Example:

    public class FileValidator : IFileValidator
    {
        public bool IsValid()
        {
            return false;
        }
    }
    
    public class DobValidator : IUserInputValidator, IFileValidator
    {
        public bool IsValid()
        {
            return false;
        }
    }
    
    public class LastNameValidator : IUserInputValidator
    {
        public bool IsValid()
        {
            return true;
        }
    }
    

    Change the factory interface to return just the specific types of validators:

    public interface IValidatorFactory
    {
        IFileValidator[] GetFileValidators();
        IUserInputValidator[] GetUserInputValidators();
    }
    

    Now register the validators accorindg to their “type”. If a validator has multiple uses, make sure to add a .Forward<> defintion for Windsor:

    var container = new WindsorContainer();
    container.AddFacility<TypedFactoryFacility>();
    container.Register(
        Component.For<IValidatorFactory>().AsFactory(),
    
        Component.For<IFileValidator>().ImplementedBy<FileValidator>(),
        Component.For<IUserInputValidator>().ImplementedBy<LastNameValidator>(),
        Component.For<IFileValidator>().Forward<IUserInputValidator>().ImplementedBy<DobValidator>()
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code: public interface IValidator<T> { bool IsValid(T obj); } public class OrderValidator:
I have a fluent, extensible validation helper like: Assert.That(aParameter).IsNotNull(); It is extensible because the
I have this interface... public interface ICheckThatDocumentExistsCommand { bool Execute( string userId, string docId
I recently inherited a VBA macro that needs to have validation logic added to
I have a validation control that has the following expression: (?=(.*\\d.*){2,})(?=(.*\\w.*){2,})(?=(.*\\W.*){1,}).{8,} That's a password
I have two validation groups: parent and child I have an add button that
Ok I have a generic interface public IConfigurationValidator<T> { void Validate(); } a class
in my Silverlight 4 project, I have a simple class implementing the interface like:
I have a controller with a constructor like so: Public Sub New(Service As ICategoryService)
i have a validation in my .net textbox where it will take only numbers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.