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 9065287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:27:47+00:00 2026-06-16T16:27:47+00:00

I have this little dependency injection container which I instantiate like: $services = new

  • 0

I have this little dependency injection container which I instantiate like:

$services = new Services();

and if I need to add parameters to it I just do:

$services->setParameter($name, $value);

and I pass this instance of $services through the constructors of some my objects and if I need something like the database handle I just go $this->services->getService('db'); and it returns an instance of the database handle and if I call that method again later it will return the same instance of the database handle it did earlier.

The thing I want to know is are dependency injection containers only for single instance objects like your $dbh, $config, $user, $auth objects?

For example, I need to create multiple instances of a Products class but if I go:

$services->setParameter('product.id', $productId);
$product[] = $services->getService('product');

It will obviously create a new instance of Product but then if I repeat that code again it will just give me back the same instance as earlier, I can obviously modify the getService() method a bit so that it can return as many new instances as I need but is that using a DIC for something it’s not made for?

So basically should a DIC only return single instances of a class like $dbh, $user etc? and not be creating objects like Orders, Products, Invoices?

  • 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-06-16T16:27:48+00:00Added an answer on June 16, 2026 at 4:27 pm

    Look at pimple’s code :

    https://github.com/fabpot/Pimple

    You can define different methods that either return a single instance , or return multiple instances depending on how the services are defines in the container.

    Pimple uses $container->share method to define shared services. then it doesnt matter how you call your services , it only matters how you define them.

    Or you could just use pimple that has everything you need already.

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

Sidebar

Related Questions

I have this little problem, that I cannot figure out which arguments to pass
I have this little NetStream movie (which I'm not allowed to show, sorry) set
have written this little class, which generates a UUID every time an object of
I have this little rake task: namespace :db do namespace :test do task :reset
I have this little question that's been on my mind for a while now.
I have this little problem. My client wanted two distinct swf on a web
I have this little text <div> Hello world<br> this is a good<br> text! <br><br>
I have this little script that shows one wisdom each day. so I have
I have this nice little MSBuild-based daily build setup that I use on my
I have this easy little form in my JavaFX application. I want to use

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.