2012-08-30 44 views
0

我想用它繼承的泛型類型來解析具體類型。使用Castle Windsor解決具有泛型類型的接口

這一切似乎工作,但是當我嘗試和呼籲解決具體類型的方法,它拋出一個異常:

{「的最佳重載的方法匹配 「MvcApplication2.Utilities.Common .CQRS.GetAlbumsByIdQueryHandler.Execute(MvcApplication2.Utilities.Common.CQRS.GetAlbumsByIdQuery)」 有一些無效參數「}

有誰知道什麼可能會造成這個?解決的類型是正確的,我認爲這可能與使用動態類型有關?

謝謝。


這裏是我的處理程序安裝:

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

,分辨率也是目前:

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

     return queryHandler.Handle(query); 

及相關類:

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
return queryHandler.Handle((dynamic)query); 
相關問題