我希望能够以这种方式在 Delphi 中编码,只需注释一个字段:
type
TMyClass = class
private
[Inject]
Factory: ISomeFactory;
...
end;
或通过归因于二传手
type
TMyClass = class
private
FFactory: ISomeFactory;
[Inject]
procedure SetFactory(const AFactory: ISomeFactory);
...
public
property Factory: ISomeFactory read FFactory write SetFactory;
end;
背景:我将旧代码移动到面向服务的架构中,发现引用服务层总是会导致类似的结构
DataModule1.ServiceLayerInstance1.SubSystemN.InvokeSomething(Params, ...);
这可能要短得多
type
Form1 = class(TForm1)
private
[Inject]
SubsystemN: ISubsystemN;
...
end;
...
SubsystemN.InvokeSomething(Params, ...);