0

I am trying to resolve a concrete type using the interface with a generic type that it inherits from.

It all seems to work, but when I try and call a method on the resolved concrete type it throws an exception of:

{"The best overloaded method match for 'MvcApplication2.Utilities.Common.CQRS.GetAlbumsByIdQueryHandler.Execute(MvcApplication2.Utilities.Common.CQRS.GetAlbumsByIdQuery)' has some invalid arguments"}

Does anyone know what could be causing this? The types that resolved are correct, I think it might have something to do with the use of the dynamic type?

Thanks.


Here is my installer for the handlers:

container.Register(AllTypes.FromAssemblyContaining<IQueryHandler>()
                                        .BasedOn(typeof (IQueryHandler<>))
                                        .WithService
                                        .AllInterfaces()
                                        .LifestyleSingleton());

And the resolution is currently:

        Type queryHandlerType = typeof (IQueryHandler<>).MakeGenericType(query.GetType());
        dynamic queryHandler = _kernal.Resolve(queryHandlerType);

        return queryHandler.Handle(query);

And the relevant classes:

public interface IQueryHandler<in TQuery> : IQueryHandler where TQuery : IQuery
{
    IQueryResult Handle(TQuery query);
}


public class GetAlbumsByIdQueryHandler : IQueryHandler<GetAlbumsByIdQuery>
{
    #region IQueryHandler<GetAlbumsByIdQuery> Members

    public IQueryResult Execute(GetAlbumsByIdQuery query)
    {
        throw new NotImplementedException();
    }

    #endregion
}

1 Answer 1

1
  return queryHandler.Handle((dynamic)query);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.