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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:01:36+00:00 2026-05-15T22:01:36+00:00

I searched my brains out and wasn’t able to find a suitable answer, so

  • 0

I searched my brains out and wasn’t able to find a suitable answer, so here we go! I have the following property in each of my forms or objects:

    private RootWorkItem m_RootWorkItem;
    [RootWorkItem(Inject = true)]
    public RootWorkItem RootWorkItem {

        get {
            if (m_RootWorkItem == null) {
                m_RootWorkItem = new RootWorkItem();
            }
            return m_RootWorkItem;
        }
    }

Note that RootWorkItem is a class I have designed that contains a collection of Services (Collection). Basically, all my services are loaded from external DLL files using reflection and Activator.CreateInstance, and put into RootWorkItem.Services.

But how on earth can I actually “inject” the very first RootWorkItem created into every other RootWorkItem marked with my attribute in my program?

How do these DI patterns ACTUALLY “DO” the injection “into” a property? I know the concepts of DI but I am trying to write my own, extremely basic DI for only one single object. I’ve been messing with reflection tons to try and find some suitable way to do this and I’m not even closed to coming up with a right way to do it.

Edited for more clearer question:
How does a DI framework/service know when an object is created that contains the property to inject?

ie:

    class MyForm : Form {
        [RootWorkItem(Inject = true)]
        public RootWorkItem RootWorkItem { get; set; }
    end class

    class Program {
        Main {
            MyForm form = new MyForm();
            form.Show();
        }
    end class

How does it know to inject the property value when the form is created, if nothing notifies the service that it was created or it needs injected?

  • 1 1 Answer
  • 1 View
  • 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-15T22:01:36+00:00Added an answer on May 15, 2026 at 10:01 pm

    You’re asking the right question: “How does it know to inject the property value when the form is created, if nothing notifies the service that it was created or it needs injected?”

    You’re also correct when you say “if nothing notifies the service that it was created or it needs injected”, then the DI framework cannot do its job.

    However, the DI framework does know, because you use the DI framework to create the object that is having its dependencies injected. In this case, you use the DI framework to create your form, so it is aware of the object and can inject dependencies.

    Instead of

    MyForm form = new MyForm(); 
    form.Show();
    

    Do

    MyForm form = DIFramework.CreateForm(typeof(MyForm));
    form.Show();
    

    Now, your DI framework knows about the object!

    Essentially, new is the enemy of DI, since it means the caller is controlling construction of the object. Instead, the caller is meant to leave that responsibility to someone else, ie, the DI framework. The caller should only ever ask the DI framework to provide/construct/configure objects.

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

Sidebar

Related Questions

Searched, but couldn't find a good answer. I have an ASP.NET application that I
I searched before asking this question. I didn't find an answer probably because I
I searched through this site to find out how to rotate a image back
Good day, I have searched far and wide but all I can find is
Searched for answer for this but couldn't find anything. The closest I could find
Searched all over, but haven't been able to find a solution. I need to
Searched for this everywhere and finally came here. I have a CORBA::WString_var as input
Searched around on SO for an answer. Found some interesting stuff but I am
Searched a lot about this problem but never found a answer, that solved it.
I searched before but couldn't find any answers. I am somewhat new to c++,

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.