使用 Delphi Spring 框架,是否可以向 GlobalContainter 注册一个泛型类型?我正在尝试做这样的事情:
TMyBaseType = class
protected
FName: string;
function GetName: string; virtual;
procedure SetName(Value: string); virtual;
public
property Name: string read GetName write SetName;
end;
TMyFirstThing = class(TMyBaseType)
protected
function GetName: string; override;
end;
TMySecondThing = class(TMyBaseType)
protected
procedure SetName(Value: string); override;
end;
TMyGenericType<T: TMyBaseType> = class
public
procedure DoSomethingWithIt(AObject: T);
function GetTheSomethingsName(AObject: T): string;
end;
// I now want to be able to use the ServiceLocator to get me an instance
// such as TMyGenericType<TMyFirstThing> or TMyGenericType<TMySecondThing>
// but I cannot figure out how to register TMyGenericType<>
......
initialization
GlobalContainer.RegisterType<TMyGenericType<>>;
// this line fails with the messages:
// [DCC Error] E2251 Ambiguous overloaded call to 'RegisterType'
// [DCC Error] E2531 Method 'RegisterType' requires explicit type argument(s)
我不确定我正在尝试做的事情是否可行,或者是否有更好/替代的方法来做到这一点?我正在使用带有最新 Spring4D 框架的 Delphi 2010。(我也有 Delphi XE5,但由于 3rd 方库,项目本身仍然是 2010 年)。任何想法或建议将不胜感激。