views:

102

answers:

1

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

+1  A: 

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

Cheers.

Krzysztof Koźmic
Thanks so much for that. Very cool to be able to auto register all services like this. Hope this post will help others. Cheers
Chev

related questions