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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:27:56+00:00 2026-06-18T07:27:56+00:00

Ok so I have my dependency injection container and a DAO that I use

  • 0

Ok so I have my dependency injection container and a DAO that I use like this to get an order for example:

$container = new DIContainer();
$orderDAO = $container->get('orderDAO');
$order = $orderDAO->fetchById($someId);

and then I have my order object which is easy to use.

The thing is what if my $order object has dependencies on a Logger, Config and one or two more objects like that, since my $orderDAO instantiates the object wouldn’t it have to have access to or be able to create those additional objects and I am pretty sure the $orderDAO object should definitely not know anything about those additional objects, especially not know how to create them.

I know I could inject the dependency injection container into the DAO when it is being instantiated (from within the DIC) and that way I would have access to any dependency my objects have from within the DAO but something about doing it that way doesn’t feel right to me for some reason and I definitely don’t want to be doing static calls all over the place either so that method is out the window.

What’s the best way to go about doing this?

Any help would be great thanks.

  • 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-18T07:27:57+00:00Added an answer on June 18, 2026 at 7:27 am

    Allow DI container to manage internal object dependencies, like assigning Logger, Config and stuff like that inside the object you instantiating – is the normal way to do the things. If for some reason you don’t want to allow DI container to do that, then you could just create default constructor and assigning this values in it.

    Actually it’s looks like you need to put inside some infrastructural things, things in that way it’s better to do that as simple as possible without some additional things, because it will get you to the unnecessary complexity.


    UPD:

    So productDAO does not have access to Config, etc… But you want that product have that. I think it’s pretty wrong from the design point of view. Because normally entities which main goal is store the data shouldn’t have any functions except their business logic. if you wan’t to do logging and configuration – you should do it inside DAO, but not in product. But anyway, if want, then just create wrapper for the things which could be changed in future (let’s say Logger) and then simply assign this value in constructor by hand.

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

Sidebar

Related Questions

I have this little dependency injection container which I instantiate like: $services = new
I have a dependency injection container setup in my application and I'm thinking that
I've got a webforms app that I'd like to use dependency injection on. I
Let's say I have a class that requires configuration, dependency injection etc. public class
I have several dependency injection services which are dependent on stuff like HTTP context.
Pretty new to dependency injection and I'm trying to figure out if this is
I have a system which is using Spring for dependency injection. I use annotation-based
In an ASP.NET MVC application when using a custom Dependency Injection container (in this
I have been looking for a way to use Unity for Dependency Injection in
When we use a dependency injection container, ideally we pull only a single-top level

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.