This application is not used any more and exists only for history. Post new tickets on the Github account.
Cette application n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #778 (confirmed enhancement)

Opened 6 years ago

Last modified 3 years ago

Inversion of Control and Dependency Injection

Reported by: laurentj Owned by:
Priority: high Milestone:
Component: jelix:utils Version: 1.0RC1
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

Christophe's patch #523 brings a kind of dependency injection / Inversion of Control, but it is not enough. We should provide a real framework for IOC/DI.

First, we should have DI on constructors. We could have too DI throw setters.

I think we could remove methods added by Christophe on jClasses, and then get/create methods could do IOC/DI transparently. For example, this methods could check if there is a mapping for the given selector. If yes, it use jClassBinding etc, and if not, it tries to load the class as usual.

To indicate the dependencies, I don't know yet if we should use an xml file or a simple ini file. We'll see.

Change History

comment:1 Changed 6 years ago by doubleface

Yes, I added these method to not cause any perf problem. But since this is now just a conditional, this is not a problem any more. I'm looking forward for your remarks. I'm glad to get another point of view of it!

comment:2 Changed 6 years ago by laurentj

I don't know yet if we would have some perf problem. But the idea is that the "user" of a class won't know if this is a real class or a binding. So a developer could bind *every* class using in a module without modifying the code of this module, without changing create() call by specific method for binding.

comment:3 Changed 6 years ago by doubleface

This is exactly the point, I think, to allow the user to modify the behavior of a class without modifying the source code of it. This is especially usefull for unit test when you want to test a class with dependencies and only test this class and not its dependencies. And the creation of things like plugins is then very easy.

And about the use of it or not in the classes of Jelix, we should think about it, maybe for form builders (for example), since the overhead is not this bad : indeed, the current implementation does not use reflection (not the case of Fabien Potencier's implementation)... But I know this should be thinked very carefully, just a proposition.

For the understanding of the current implementation, I am working on an article to put on the wiki.

comment:4 Changed 6 years ago by doubleface

Here is the article (in french)

comment:5 Changed 6 years ago by laurentj

  • Type changed from bug to enhancement

comment:6 follow-up: ↓ 8 Changed 5 years ago by ametaireau

Here is my implementation of a DI container, that could be included in jelix. http://www.notmyidea.org/?p=189&preview=true&preview_id=189&public=1&nonce=dbae6e73f3

comment:7 Changed 4 years ago by laurentj

  • Milestone changed from Jelix 1.2 beta to Jelix 1.3

comment:9 Changed 4 years ago by laurentj

  • Priority changed from highest to high

comment:10 Changed 3 years ago by laurentj

  • Milestone Jelix 1.3 deleted

comment:11 Changed 3 years ago by laurentj

  • Status changed from new to confirmed
Note: See TracTickets for help on using tickets.