No component for supporting the service - Fluent registration and resolution of Generic with generics parameters

49 views
Skip to first unread message

Gustavo Mickiewicz

unread,
Jan 8, 2015, 10:41:11 PM1/8/15
to castle-pro...@googlegroups.com
If i use one-by-one component registration everything resolves ok.. my problem is fluent registration, any thoughts?

Example

    public class MyFilter:Filter {}
                         
   
public class MyEntity:Entity {}

   
public class ReadCommandHandler<TEntity,TFilter> : ICommandHandler<IReadCommand<TFilter>, IEnumerable<TEntity>> where TEntity : Entity where TFilter : Filter




Installer

    container.Register(Types.FromThisAssembly().BasedOn(typeof(ICommandHandler<,>)).WithService.AllInterfaces());



   
this results in (debugger view)

    ReadCommandHandlerTEntity·, ·TFilter·> / ICommandHandler< IReadCommandTFilter·>, IEnumerableTEntity·>>    



so it seems is ok .. but then if i tried this

   
var biz = container.Resolve(typeof(ICommandHandler<IReadCommand<MyFilter>,IEnumerable<MyEntity>>))



or this

    var biz = container.Resolve(typeof(ICommandHandler<IReadCommand<Filter>,IEnumerable<Entity>>))



the result is "No component for supporting the service"

whats the matter with this?

may be i have to use strategy GenericImplementationMatchingStrategy?

thanx




hammett

unread,
Jan 22, 2015, 7:34:27 PM1/22/15
to castle-pro...@googlegroups.com
I'm not so sure we support this nested level of generic arguments
resolution. I thought Kryz worked/gave-up on that a while ago. It's
not a trivial thing.

I'd encourage you check our test cases, if we do support them it
should be easy to spot with the other generic resolution test cases.
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to castle-project-u...@googlegroups.com.
> To post to this group, send email to castle-pro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/castle-project-users.
> For more options, visit https://groups.google.com/d/optout.



--
Cheers,
hammett
http://www.d-collab.com/
http://www.hammettblog.com/

veihan

unread,
Jan 30, 2015, 8:48:01 AM1/30/15
to castle-pro...@googlegroups.com
Hi,

Well it will Resolve, but at some point you need to concertize your ReadCommandHandler with typed generics.

here's modification to your example:

    [TestFixture]
    public class GustavoMickiewiczIssue
    {
        public abstract class Filter { }
        public abstract class Entity { }
        public class MyFilter : Filter { }
        public class MyEntity : Entity { }
        public interface ICommandHandler<T1, T2> { }
        public interface IReadCommand<T> { }
        public abstract class ReadCommandHandler<TEntity, TFilter> : ICommandHandler<IReadCommand<TFilter>, IEnumerable<TEntity>>
            where TEntity : Entity
            where TFilter : Filter { }

        public class ReadCommandHandler1 : ReadCommandHandler<MyEntity, MyFilter> { }

        [Test]
        public void Resolve_ICommandHandler_NotNull()
        {
            // Arrange.
            var container = new WindsorContainer();
            container.Register(Classes.FromThisAssembly().BasedOn(typeof(ICommandHandler<,>)).WithService.AllInterfaces());

            // Act.
            var result = container.Resolve<ICommandHandler<IReadCommand<MyFilter>, IEnumerable<MyEntity>>>();

            // Assert.
            Assert.That(result, Is.Not.Null);
        }
    }
Reply all
Reply to author
Forward
0 new messages