[Lazarus] Inversion of control (IoC) and Dependency injection (DI)
luiz americo pereira camara
luizmed at oi.com.br
Mon Jan 12 03:43:06 CET 2015
2015-01-11 17:12 GMT-03:00 silvioprog <silvioprog at gmail.com>:
> On Mon, Jan 5, 2015 at 5:07 PM, luiz americo pereira camara <
> luizmed at oi.com.br> wrote:
>
>> I created a IoC Container that can be found at
>> https://code.google.com/p/luipack/source/browse/trunk/luicomponents/luiioccontainer.pas
>> . It has no dependencies.
>>
>
> Awesome!
>
Thanks.
>
> With it is possible to implement Service Locator and Property Injection
>> patterns. Constructor Injection is not possible due to lacking of Extended
>> RTTI support in fpc.
>>
>
> Can you send a small (and isolated) sample showing how to use it?
>
There's a demo in demos/ioccontainer folder
In a real project, in the app start, i do:
FPresentations := TPresentationManager.Create(Self);
Services.Register(IPresentationManager, FPresentations);
When i need the service i do:
FPresentations :=
IPresentationManager(Services.Resolve(IPresentationManager));
The global, nor the actual implementation is exposed, making easier to test.
There's still a dependency to the container (Services), this is the whole
point of criticism to service locator pattern.
In the other side there always be a place where the dependency is set, even
in other DI patterns.
BTW: Custom Attributes support would help to have a nicer Property
>> Injection implementation
>>
>
> I've plan to use something like this (CDI inspirations:
> http://cdi-spec.org):
>
>
Seems a full ORM plus a MVC like framework.
I'm more modest. I use these classes to make modular code thus a bit more
maintanable.
All in all i use the IoC container little, in my project i register only
two interfaces. In other places, i configure the dependency manually
Luiz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150111/20cc45d5/attachment-0003.html>
More information about the Lazarus
mailing list