1
我有以下類別:使用simpleinjector註冊opengeneric
public interface IDbCommandHandler<in TCommand, out TOutput>
where TCommand : IDbCommand
{
TOutput Handle(TCommand command);
}
public class SubIdentifierItemCreateCommand<TItemType, TDefaultValues>
: BaseDbCommand
where TItemType: TDefaultValues
{
}
public class SubIdentifierItemCreateCommandHandler<TItemType, TDefaultValues>
: BaseDbCommandHandler<SubIdentifierItemCreateCommand<TItemType, TDefaultValues>, TItemType>,
IDbCommandHandler<SubIdentifierItemCreateCommand<TItemType, TDefaultValues>, TItemType>
where TItemType: class, TDefaultValues, IItemForGenericItemByIdentifierRetriever , new()
{
}
我需要註冊SubIdentifierItemCreateCommandHandler
爲單-opengeneric,以處理 IDbCommandHandler<SubIdentifierItemCreateCommand<,>,>
類型的服務的任何請求。
這可能嗎?我以各種方式嘗試過,並且總是遇到錯誤。
_container.RegisterSingleOpenGeneric(
typeof(IDbCommandHandler<,>),
typeof(SubIdentifierItemCreateCommandHandler<,>));
_container.RegisterOpenGeneric(
typeof(IDbCommandHandler<,>),
typeof(SubIdentifierItemCreateCommandHandler<,>));
// this one is throws a compile-time error, that you cannot
// use partial open types.
_container.RegisterManyForOpenGeneric(
typeof(IDbCommandHandler<SubIdentifierItemCreateCommand<,>,>),
typeof(SubIdentifierItemCreateCommandHandler<,>));
我希望能夠調用以下工作:
var item = _container.GetInstance<
IDbCommandHandler<
SubIdentifierItemCreateCommand<
SectionData,
ISectionDataDefaultValues>,
SectionData>>();
偉大的仿製藥母親!這是一些瘋狂的屁股通用狗屎,你已經到了那裏。請給我一點時間來解釋你的問題。 – Steven 2013-02-21 22:38:00