我有以下课程:
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
为 singleton-open-generic,以处理对类型服务的任何请求
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>>();