Feature #11311
Enable dependency injection for domain objects
| Status: | Resolved | Start date: | 2011-01-21 | |
|---|---|---|---|---|
| Priority: | Must have | Due date: | ||
| Assignee: | Bastian Waidelich | % Done: | 100% |
|
| Category: | Extbase: Object | |||
| Target version: | Extbase 1.4 | |||
| Has patch: | Tags: | |||
| Votes: | 0 |
Description
Dependency injection is currently not available for domain objects that are created automatically.
Solution:¶
Replace "new $className" with ObjectManager->create().
I don't know which side-effects not using the unserialize() function in the DataMapper has, but I couldn't find any and the unit tests don't show any difference after applying the patch.
Related issues
| related to Extbase MVC Framework - Bug #12740: Regression because initializeObject is not called anymore... | Resolved | 2011-02-02 | ||
| related to Extbase MVC Framework - Task #13816: use the objectManager to create empty domain objects inst... | Resolved | 2011-03-14 |
Associated revisions
[+FEATURE] Extbase: Enable Dependency Injection for Domain Models
In order to avoid the constructor to be called,
domain objects are created by using PHPs unserialize() function.
This has the side-effect, that we need to inject
dependencies "manually" for those.
This is accomplished by adding a helper function
getEmptyObject() to the Object Container.
Thanks to Pascal Jungblut for the patches!
Change-Id: I49edab54eb810abc894f3f59fe8c46cf4ddfa464
Fixes: #11311
History
Updated by Pascal Jungblut over 2 years ago
- File 11311_v2.patch added
Moved the unserialize() call to the object-container and added a function "getEmptyObject".
Updated by Pascal Jungblut over 2 years ago
- File 11311_v3.patch added
Forgot to add unit test getEmptyObjectReturnsInstanceOfSimpleClass.
Updated by Sebastian Kurfuerst over 2 years ago
Hey,
could you please adjust your patch to current trunk? I just re-wrote the DI container to make it more understandable.
Thanks and greets,
Sebastian
Updated by Daniel Poetzinger over 2 years ago
I guess replacing the unserialize hack with just "new" has the sideeffect that __wakup is not called:
@see abstract class Tx_Extbase_DomainObject_AbstractDomainObject
/**
* This is the magic __wakeup() method. It's invoked by the unserialize statement in the reconstitution process
* of the object. If you want to implement your own __wakeup() method in your Domain Object you have to call
* parent::__wakeup() first!
*
* @return void
*/
public function __wakeup() {
$this->initializeObject();
}
So after the ->create call the method initializeObject should be called.
Updated by Sebastian Kurfuerst over 2 years ago
- Category set to Extbase: Object
- Status changed from New to Needs Feedback
- Priority changed from Should have to Could have
- % Done changed from 0 to 20
Nice feature in general, it just needs to be adjusted to the current state in order to have it committed. Would you be willing to do this?
Greets, Sebastian
Updated by Pascal Jungblut over 2 years ago
Daniel Poetzinger wrote:
I guess replacing the unserialize hack with just "new" has the sideeffect that __wakup is not called:
Did you have a look at the patch? I just moved the call of unserialize to the ObjectManager, so it can inject properties after unserialization.
Sebastian:
Sure, I will adjust the patch as needed. But I'm a little bit in stress right now. It may take one or two days until I find the time.
Updated by Sebastian Kurfuerst over 2 years ago
- Tracker changed from Bug to Feature
- Target version set to Extbase 1.3.0
That's great news, thanks for taking care!
Greets,
Sebastian
Updated by Sebastian Kurfuerst over 2 years ago
- Target version changed from Extbase 1.3.0 to Extbase 1.3.0RC1
Updated by Pascal Jungblut over 2 years ago
- File 11311_v4.patch added
Just adapted the patch to your changes. Great refactoring, btw.
Updated by Felix Oertel over 2 years ago
- Status changed from Needs Feedback to Accepted
- Priority changed from Could have to Must have
- Target version changed from Extbase 1.3.0RC1 to Extbase 1.3
- Start date changed from 2010-12-07 to 2011-01-21
unfortunately this won't make it into rc1. it's a non-trivial change which has to be tested and some unit-tests written for.
anyway thanks for your work on this ...
Updated by Marc Bastian Heinrichs over 2 years ago
- Target version changed from Extbase 1.3 to Extbase 1.4
Updated by Bastian Waidelich over 2 years ago
- Status changed from Accepted to Resolved
- % Done changed from 20 to 100
Applied in changeset e86f70d024821c08748bee2b43dbe48481c0005f.
Updated by Marc Bastian Heinrichs about 2 years ago
- Assignee set to Bastian Waidelich