Community

Dependency Injection Implementation

This is the best place to ask your questions.

Dependency Injection Implementation

Postby darscan on Sun May 03, 2009 1:27 pm

Hello,

I've just discovered the Lion Framework - it looks great. I've been searching for a loosely-coupled Dependency Injection driven PHP framework for a while.

How dependent is Lion on it's own Spring-like library? IE, how easy/difficult would it be to swap out the Lion DI library and use something else in it's place? I prefer Guice style DI - dependencies defined by code rather than external XML configuration files.

Are the Lion components loosely coupled enough to be managed by a different DI/IoC framework? If I wanted to bypass the MVC/routing system (to build a lightweight RPC/services layer) would that be possible?

Many thanks,
darscan
darscan
 
Posts: 2
Joined: Sun May 03, 2009 1:19 pm

Re: Dependency Injection Implementation

Postby aparraga on Mon May 04, 2009 4:20 pm

To bypass the MVC/routing is really easy:
All you need to do is to set the LION_AUTODISPATCH_CLIENT_REQUEST constant to false before including the lion.php file (which is the file you need to include to make the framework works).
This value let the framework know to DO NOT DISPATCH requests as soon as they arrive to the server. You'll do that by yourself.

So, you can use the IoC capabilities of the framework without passing through the MVC nor the URL routing nor whatever other layer that you don't want to use.

In the other hand, why you prefer to use IoC programatically better than declaratively within the configuration xml files?
aparraga
Site Admin
 
Posts: 37
Joined: Thu Nov 08, 2007 8:02 am

Re: Dependency Injection Implementation

Postby darscan on Tue May 05, 2009 3:25 pm

Thanks for the response! Hopefully I'll get some time to play around with the framework in the next couple of weeks.

With regards to DI configuration styles: I suppose it's just a stylistic preference, but my applications generally have multiple application layers - the PHP side is just one of them, I do a lot of Flash and Flex with remoting - so I like to keep certain things/styles consistent across tiers. Perhaps I will enjoy the XML configuration once I've used it in the context of the Lion framework :)

Regards,
darscan
 
Posts: 2
Joined: Sun May 03, 2009 1:19 pm

Re: Dependency Injection Implementation

Postby raul on Fri May 15, 2009 4:13 pm

Hi,

I also work with multiple client applications, like flex, javafx, mobile, etc. and for that, I built a PHP app in an ESB style app, a ServiceProvider side (the service bus app) which listens for messages in a certain protocol, translates the message to PHP code, and transforms the results back to the used protocol for response. And a consumer side (the client) that uses a specific message protocol (AMF, JSON, etc), I used the adapter pattern for transforming the requests before processing them with the classes, and transforming results back to the protocol and send a response. DI comes into place for adapter choosing, depending on the protocol used, the app chooses the adapter.

I'm a newbie with lion, but I'm gonna see if I can use my ServiceProvider and adapt it to lion, I guess the hardest work would be using my ORM (doctrine) with lion, I still don't know if lion has any DBMS-dependent code.

It would be interesting to implement the ESB with lion.
raul
 
Posts: 1
Joined: Fri May 15, 2009 4:01 pm

Re: Dependency Injection Implementation

Postby aparraga on Mon May 18, 2009 8:21 am

Hi,

I'm in love with ESB apps. In fact, almost our recent works are based on combining an ESB (we are working with mule) as the backend and PHP (we are working with Lion PHP Framework :) as the frontend.
All our facades, factories, strategies, model layers, etc... are configured by using the lion DI capabilities.
Going back to your questions, lion does not have any dependency, nor with an ORM nor with whatever third-party library. Lion brings out of the box some facades to some libraries (i.e. log4php facade, memcache facade, etc...), but again: it does not depends on a concrete implementation.
So, you are able to configure your own ORM with the lion. Take a look at http://www.lionframework.org/d.orm (some functional samples are coming soon).
aparraga
Site Admin
 
Posts: 37
Joined: Thu Nov 08, 2007 8:02 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron