Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:28:29+00:00 2026-05-29T15:28:29+00:00

Consider this code: public function showActiveJobsAction($slug) { $em = $this->getDoctrine()->getEntityManager(); $category = $em->getRepository(‘JobeetBundle:Category’)->findBySlug($slug); if

  • 0

Consider this code:

public function showActiveJobsAction($slug)
{
     $em = $this->getDoctrine()->getEntityManager();
     $category = $em->getRepository('JobeetBundle:Category')->findBySlug($slug);
     if (! $category) {
        throw $this->createNotFoundException('Unable to find Category entity.');
     }

     $jobService = $this->container->get('job_service');
     $category = $jobService->populateCategoryByItsActiveJobs($category);

     return $this->render('JobeetBundle:Category:jobs.html.twig', array(
        'category'      => $category,
    ));        
}

job_service need JobeetBundle:Category repository to work. The repository is passed to service constructor. It’s all defined in services.yml

So in this case I end up with two instance of JobeetBundle:Category repository class?

If yes how can I change my design to do it better?

Probably it’s better to create code just like:

$jobService->getCatetoryWithActiveJobsByItsSlug($slug)

but I still wonder if container looks for object existance before create it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:28:29+00:00Added an answer on May 29, 2026 at 3:28 pm

    When you get a service from the container, by default, you get always the same instance. It is also the same instance when this service is injected into another one.

    So you don’t have two worry, you get only one instance of the service job_service.

    Here is an extract from the Symfony2 book, chapter Service Container:

    As an added bonus, the Mailer service is only created once and the same instance is returned each time you ask for the service. This is almost always the behavior you’ll need (it’s more flexible and powerful).

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code : class App { public static function log($msg) { echo $msg;
consider this code : Class Controller_xyz extends Controller { protected $res=' '; public function
Consider this code: public <T> List<T> meth(List<?> type) { System.out.println(type); // 1 return new
consider this code block public void ManageInstalledComponentsUpdate() { IUpdateView view = new UpdaterForm(); BackgroundWorker
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
Consider this code (Java, specifically): public int doSomething() { doA(); try { doB(); }
Consider this trivial function: public static bool IsPositive(IComparable<int> value) { return value.CompareTo(0) > 0;
Consider this code sample: public abstract class Parent { public int val; public Parent()
Consider this code: template <typename T> class String { public: ... String(T* initStr) {
Consider this class: class Test { public $obj; function __construct ($obj) { $this->obj =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.