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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:34:24+00:00 2026-05-13T17:34:24+00:00

My situation is essentially this: I have a class called Foo which has dependencies

  • 0

My situation is essentially this: I have a class called Foo which has dependencies A and B, all of which are internal to a library. Instances of Foo will be created by user of the library, and they should not require knowledge of the dependencies.

Internally of course I would like Foo to remain decoupled from the concrete implementations of A and B. I had considered a simple static factory class, however it would be necessary to configure this somehow for the dependencies (say Factory::$_staticAttr = x) and this seems wrong as it would essentially mean my static class has a state.

I’ve also been thinking some XML or otherwise configured dependency injection container, however it then raises the question of how to make the configured DIC’s instance accessible without something messy like having it in a registry object.

I’m striving for some trivial method for the end user to generate an instance of Foo with everything injected, while keeping all the details of dependencies etc hidden within the library.

I’ve read around and the solution has not really made itself obviously to me as yet, so I’d appreciate any input :).

  • 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-13T17:34:25+00:00Added an answer on May 13, 2026 at 5:34 pm

    I myself use a dependancy injection container (a static factory) for these things.
    Consider reading this post: http://www.potstuck.com/2009/01/08/php-dependency-injection/

    I’m striving for some trivial method
    for the end user to generate an
    instance of Foo with everything
    injected, while keeping all the
    details of dependencies etc hidden
    within the library.

    I would definitely go for a factory in that case.

    UPDATE

    That’s what static classes are for. They represent a certain state, as in this case. You only need one db adapter (per application|class|package), so you can reuse the same one again and again.
    Using global would be a lot more hackyish 😉

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

Sidebar

Related Questions

Essentially, the situation is as follows: I have a class template (using one template
I have a base class Foo that is concrete and contains 30 methods which
This is a complicated situation, but essentially what has happened here is that our
My situation is this: I have an html page which contains a table of
Situation: I have an index page which loads pages into it with ajax as
OK, the situation is we have a class, PatientDto , and a DynamicProxy generated
I have a set of classes which are all derived from a common base
One of my classes has a field which contains a Set. This field is
I have a unique situation with setStringValue: and hoping someone could clear this up:
Ok I will try to explain this as much as possible. I have a

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.