Almost always you will need configuration ability for your Bundle & validation for this config files. And if not, you need to tell Symfony2 that your extension exists & how to load it. Remember, not all extensions needs DIC configurations & some of them could be configured right inside Extension itself. So, Extension is the entry point for Symfony2 bundles, not DIC configurations! Anyway, Extension file for loading DIC config will take only ~10 lines of real code[1]. It's very small footprint & not a problem at all for bundle developers, i think!
[1] https://github.com/everzet/EverzetRestfulControllersBundle/blob/master/DependencyInjection/RestfulControllersExtension.php --- http://about.me/everzet/bio On Fri, Dec 17, 2010 at 14:27, Leon van der Ree <[email protected]>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> > > 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
