Reputation: 12438
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
}
Upvotes: 0
Views: 697