title: Do Symfony2 Services Always Need to be Declared in a Bundle?
body: <p>In Symfony2, a service is defined as [emphasis mine]:</p>
  
  <blockquote>
    <p>A Service is a generic term for any PHP object that performs a
    specific task. A service is usually used "<strong>globally</strong>", such as a
    database connection object or an object that delivers email messages.
    In Symfony2, services are often configured and retrieved from the
    service container. An application that has many decoupled services is
    said to follow a service-oriented architecture.</p>
  </blockquote>
  
  <p>With "globally" being the key word, all the examples I see of how to define a service have the service declared within an existing bundle? Here's an example from <a href="http://www.martinsikora.com/symfony2-and-dependency-injection" rel="nofollow" title="MartinSikora.com">MartinSikora.com</a></p>
  
  <pre><code>&lt;?php
      // Bundle/HelloBundle/Services/MyService.php
      namespace Bundle\HelloBundle\Services;
  
      class MyService {
  
          public function sum($n1, $n2) {
              return $n1 + $n2;
          }
  
      }
  ?&gt;
  </code></pre>
  
  <p>He then uses it from within the Hello Controller:</p>
  
  <pre><code>&lt;?php
  // Bundle/HelloBundle/Controller/HelloController.php
  namespace Bundle\HelloBundle\Controller;
  
  class HelloController extends Controller {
  
      public function indexAction() {
          $number = $this-&gt;get('my_service')-&gt;sum(12, 37);
          // this returns 49
  
          /*
          ...
          */
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Notice how his example service is declared inside of the HelloBundle bundle in a folder labeled "Services". Wouldn't it be better if the "Services" folder were stored one or more levels higher outside of any specific bundle since services are meant to be used across the entire application?</p>
  
  <ul>
  <li>What's the best practice here? </li>
  <li>Is the service only available to controllers within the HelloBundle Bundle?</li>
  <li>Why is it usually done this way?</li>
  </ul>