Resolving a Generic with a Generic parameter in Castle Windsor

Posted by Aaron Fischer on Stack Overflow See other posts from Stack Overflow or by Aaron Fischer
Published on 2009-11-04T21:47:09Z Indexed on 2010/05/18 5:40 UTC
Read the original article Hit count: 472

I am trying to register a type like IRequestHandler1[GenericTestRequest1[T]] which will be implemented by GenericTestRequestHandler`1[T] but I am currently getting an error from Windsor "Castle.MicroKernel.ComponentNotFoundException : No component for supporting the service " Is this type of operation supported? Or is it to far removed from the suppored register( Component.For(typeof( IList<>).ImplementedBy( typeof( List<> ) ) )

below is an example of a breaking test. //////////////////////////////////////////////////////

public interface IRequestHandler{}

public interface IRequestHandler<TRequest> : IRequestHandler where TRequest : Request{} 

public class  GenericTestRequest<T> : Request{} 

public class GenericTestRequestHandler<T> : RequestHandler<GenericTestRequest<T>>{}

[TestFixture]
public class ComponentRegistrationTests{
   [Test]
   public void DoNotAutoRegisterGenericRequestHandler(){

var IOC = new Castle.Windsor.WindsorContainer();
var type = typeof( IRequestHandler<> ).MakeGenericType( typeof( GenericTestRequest<> ) );
IOC.Register( Component.For( type ).ImplementedBy( typeof( GenericTestRequestHandler<> ) ) );

var requestHandler = IoC.Container.Resolve( typeof(IRequestHandler<GenericTestRequest<String>>));

Assert.IsInstanceOf <IRequestHandler<GenericTestRequest<String>>>( requestHandler );
Assert.IsNotNull( requestHandler );
}
}

© Stack Overflow or respective owner

Related posts about castle-windsor

Related posts about .NET