zikula / ExtensionLibrary

Browsable Zikula Extensions library
6 stars 0 forks source link

interesting DI idea #48

Open craigh opened 10 years ago

craigh commented 10 years ago

https://groups.google.com/d/msg/doctrine-user/ZLttjX1ZTPQ/5GgM8_JDZmwJ

I don't relly like the usage of strings when the same value is used all over the project. To write 100x 'MyNamespace\Model\MyEntity' is quite bad if you want to refactor things some times.

response:

Declare the entity classes in config files, inject the repositories with DI

parameters:
    my.entity.class: MyNamespace\MyEntity

service:
    my.repository:
        class: MyRepo
        factory_service: doctrine.orm.entity_manager
        factory_method: getRepository
        arguments:
            - %my.entity.class%

this could maybe be something to try (in any project, I just decided to post it here)

cmfcmf commented 10 years ago

Interesting indeed! I like it!

Guite commented 10 years ago

Yes, this is very recommended. It also allows to extend/override entity classes with ease, thus MOST-based modules do it similarly utilising a factory class for retrieving new entity instances or corresponding repositories.