Yes, I was *hoping* someone would say exactly that. The official answer
should be:

* Create the new service resource in your bundle (e.g. config.xml)
* Import it from your app config file

Done.

The idea of creating the full DI extension for further customization would
be an exercise that's left to be explained in more advanced documentation
and used by more advanced users.

Ryan Weaver
Lead Programmer - iostudio - Nashville, TN
http://www.iostudio.com
http://www.thatsquality.com
Twitter: @weaverryan


On Fri, Dec 17, 2010 at 8:01 AM, Fabien Potencier <
[email protected]> wrote:

> On 12/17/10 1:27 PM, Leon van der Ree wrote:
>
>> Hi all,
>>
>> I finally had some time to take a look at Symfony2 and am again
>> pleased with the result!
>>
>> In my project I extended the Routing Loader with an extra feature, to
>> be able to define routing rules in my database (I will post my work to
>> github soon). However I am wondering if I have setup the dependency
>> injection correctly, since I think it is very cumbersome to add a new
>> service to the container.
>>
>> What I had expected was that I should describe the new service in a
>> xml, like:
>>
>>
>> <?xml version="1.0" ?>
>>
>> <container xmlns="http://www.symfony-project.org/schema/dic/services";
>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>>     xsi:schemaLocation="http://www.symfony-project.org/schema/dic/
>> services
>> http://www.symfony-project.org/schema/dic/services/services-1.0.xsd";>
>>
>>     <parameters>
>>         <parameter key="routing.loader.db.class">Bundle\CmsBundle
>> \Routing\Loader\DbLoader</parameter>
>>     </parameters>
>>
>>     <services>
>>         <service id="routing.loader.db" class="%routing.loader.db.class
>> %">
>>             <tag name="routing.loader" />
>>             <argument type="service" id="doctrine.orm.entity_manager" /
>>
>>>
>>>          </service>
>>     </services>
>> </container>
>>
>
> Import this file from your config.xml and you're done.
>
> Fabien
>
>
>  However this xml-config is not automatically loaded, to accomplish
>> this I had to write a Bundle\CmsBundle\DependencyInjection
>> \CmsExtension class, in which I had to define 4 functions:
>> configLoad(), with
>>     $loader = new XmlFileLoader($container, __DIR__.'/../Resources/
>> config');
>>     $loader->load('routing.xml');
>> getXsdValidationBasePath() and getNamespace() that I don't use but are
>> defined in the interface
>> and finally getAlias() which I do use, since:
>>
>> I had to mention this alias in my config.yml of my app as well, else
>> the CmsExtension is not instantiated and so the service is still not
>> loaded
>>
>> So all in all I had to write
>> - the service container xml
>> - write a CmsExtension-class with functions that I don't use
>> - and mention the alias in my config.yml in order to make the
>> container config loaded
>>
>> while the structure of the service container xml is exactly the same
>> as the one for the routing from Symfony, I would have expected this
>> could be done a little easier. Maybe only writing the service
>> container xml, that gets loaded automatically when placed in the
>> correct folder of your bundle, or if this is too much magic, adding a
>> simple instruction somewhere (E.G. in the Bundle\CmsBundle\CmsBundle
>> class ) to define where the service container xml is located.
>>
>> Am I maybe missing something, or is there still some room to improve
>> this.
>>
>>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<symfony-devs%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to