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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:30:40+00:00 2026-05-22T01:30:40+00:00

I am thinking to refactor some code in a MVC application built in PHP

  • 0

I am thinking to refactor some code in a MVC application built in PHP to utilise Dependency Injection Containers.

I am currently looking at the Symfony DI component, which looks quite good. I understand the basics of DI and DI containers, but do I use 1 global container or multiple containers throughout my application?

For example, let’s say I have:
“User” class requires the dependencies: “ActiveRecord” and “Sessions”
“SiteStatistics” class requires the dependencies: “ActiveRecord” and “Sessions”

Should the User and SiteStatistic objects be placed in different containers? Or should I have a global container that contains everything I ever need to create?

Thank you 🙂

  • 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-22T01:30:41+00:00Added an answer on May 22, 2026 at 1:30 am

    The beatuy of DI containers is that you can define your dependencies and the container gives you the objects with all the dependencies (and their dependencies in turn, etc). The more objects you place in the container, the higher probability that you can use these objects together without calling “new” in one of the objects.

    So – if the “Sessions” object for the User and the “Sessions” object for the SiteStatistics are the same, then by all means use only one container. If they are different, still use one container, but use different identifiers for each session object when you configure the dependencies.

    If you are looking for ways to isolate the User session data from the SiteStatistics data, I think the DI container is the wrong place for this.

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

Sidebar

Related Questions

I am currently working on some Java code that has a lot of ActionListeners
I have a php application that has about 50-55 code files. The file that
I have a problem with some code I need to refactor. Right now it
Thinking about avoiding code replication, I got a question that catches me every time
Currently thinking about pitching the argument for us migration from vs 2005 (winforms) to
I've been thinking about ways to refactor a fairly expansive class/utility library I have,
I'm looking for a way to create some kind of value type hierarchical class
I'm implementing some code using the java.util.concurrency framework. I will be passing a collection
I wrote this code. It's really ugly. I would like to refactor it. I
I'm building an MVC application that consists of entities that can be referenced by

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.