2015-01-11 17:12 GMT-03:00 silvioprog <[email protected]>: > On Mon, Jan 5, 2015 at 5:07 PM, luiz americo pereira camara < > [email protected]> 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
-- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
