gpt4 book ai didi

delphi - Delphi 是否有使用 [Dependency] 等属性的 DI 框架?

转载 作者:行者123 更新时间:2023-12-03 15:27:47 26 4
gpt4 key购买 nike

是否可能,如果是的话,Delphi(Win32)中是否有依赖注入(inject)容器的实现,它支持基于“自定义属性”的注入(inject),看起来像

TDiExample = class(TObject)
private
[Dependency]
AOther: ISomeInterface

...
end;

(有关 .Net 对应项,请参阅 Dependency Injection and .NET Attributes;有关 Delphi Win32 DI 框架,请参阅 https://stackoverflow.com/questions/812599/is-there-a-dependency-injection-framework-for-delphi-or-free-pascal)

到目前为止,我已经看到过使用直接调用依赖注入(inject)容器的示例,例如:

var
AOther: ISomeInterface
...
AOther := DiContainer.Get(ISomeInterface) as ISomeInterface;

最佳答案

是的,这是可能的。我的简单 DI 容器将可以在下一个版本中执行此操作,并且还会有许多其他改进。在此处查看当前版本 https://github.com/danieleteti/delphidicontainer

关于delphi - Delphi 是否有使用 [Dependency] 等属性的 DI 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com