Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Castle Windsor Registration of Interface and Abstract Implementations

I am trying to work out how to auto register implementations of an generic abstract class or interface. Here are my classes:

public abstract class AbstractValidator<T> : IValidator<T>
{
   public void Validate(T)
   {
      ...
   }
}

public class CustomerValidator:AbstractValidator<Customer>
{
  ...
}

I am trying the following:

_container = new WindsorContainer();
_container.Register(
    AllTypes.FromAssemblyContaining<ValidationPatterns>()
         .BasedOn<IValidator>()
         .WithService.Base()
    }));

IValidator<Customer> val = _container.Resolve<IValidator<Customer>>();

Any tips greatly appreciated.

Cheers

like image 992
Samuel Goldenbaum Avatar asked Oct 07 '10 11:10

Samuel Goldenbaum


Video Answer


1 Answers

You're close. Should be BasedOn(typeof(IValidator<>)) that is the generic open type.

Cheers.

like image 165
Krzysztof Kozmic Avatar answered Oct 16 '22 19:10

Krzysztof Kozmic