今天发现了一个delhpi的Spring框架,而且这家还是易博龙的合作伙伴。
转自官方wiki。
Architecture¶ 系统架构
The Delphi Spring Framework consists of the following libraries:
Delphi Spring 框架包含如下这些库:
- Spring.Base
Provides the fundamental classes for the framework. Some of them are designed based on the .Net framework.
- Spring.Base
提供框架的基本类,其中的一部分是基于.net 框架设计。
- Spring.Core
Provides the higher level and core features. e.g. Inversion Of Control (IoC) container.
-Spring.Core
提供更高层的以及核心特性,例如控制反转(IoC)容器。
- Spring.Extensions
Includes some useful features such as Numbering.
-Spring.Extensions
包含一些实用功能例如数值处理。
Dependency Injection by the IoC container¶
IOC容器依赖注入
The following code demonstrates how to use the IoC container: (Register->Build->Resolve->Release)
下面的代码是使用IoC容器的示例:(注册-》构建-》解析-》释放)
// uses Spring.IoC; var container: TContainer; customer: TCustomer; begin container := TContainer.Create; try container.RegisterComponent<TRealCreditCardService> .Implements<ICreditCardService> .AsSingleton; container.RegisterComponent<TCustomer>; container.Build; customer := container.Resolve<TCustomer>; // Auto-wiring try customer.PayByCreditCard(...); finally container.Release(customer); end; finally container.Free; end; end.
看到了么,是四大步骤Register->Build->Resolve->Release,注册->构建->解析->释放。 Java Spring 出到3了,加入了注解功能以及新的配置方法,只看了看2.5的 ,3 的新增还没有细看,不知是不是也能支持直接在语言代码中自动装配,看到delphi spring确实简洁,整个的注册构建和装配(解析)以及释放的过程都在代码中实现,而且很直观明晰。