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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:37:22+00:00 2026-06-15T08:37:22+00:00

I have a class (MathController) that knows how to refresh a Math component. That

  • 0

I have a class (MathController) that knows how to refresh a Math component.
That class uses a helper class for determining when to trigger the refresh, based on a time schedule.

What I’d like to do is to add the helper class to my IoC container.

Currently, the IoC creates the MathController. Since the helper class needs to receive an Action from the MathController, I don’t know how to do that without getting into a circular dependencies scenario.

This is a sample I’ve created as an example of the scenario.

void Main()
{
    var mathController = new MathController();
}

class MathController
{
    private readonly StateMonitor _stateMonitor;

    public MathController()
    {
        _stateMonitor = new StateMonitor(RefreshMath);
        _stateMonitor.Monitor();
    }

    public void RefreshMath()
    {
        Debug.WriteLine("Math has been refreshed");
    }
}

class StateMonitor
{
    private readonly Action _refreshCommand;

    public StateMonitor(Action command)
    {
        _refreshCommand = command;
    }

    public void Monitor()
    {
        Debug.WriteLine("Start monitoring");
        Thread.Sleep(5000);
        Debug.WriteLine("Something happened, we should execute the given command");
        _refreshCommand();
    }
}
  • 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-15T08:37:23+00:00Added an answer on June 15, 2026 at 8:37 am

    Your IoC container may support some way to do this. For instance, NInject allows you to register a provider (basically a factory method) which could handle the initialization for you. It might help if you said which IoC container & version you’re using.

    Another way would be to inject a StateMonitorFactory into the MathController, instead of the StateMonitor itself. The factory would then build the StateMonitor. So the MathController might look like:

    public MathController(StateMonitorFactory fact)
    {
        _stateMonitor = fact.CreateStateMonitor(RefreshMath);
        _stateMonitor.Monitor();
    }
    

    A third option would be to have the StateMonitor have an initialization method. In that case the StateMonitor constructor would become parameterless, but you’d add another method to it with a signature like Start(Action command), and MathController would be responsible for calling that.

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

Sidebar

Related Questions

I have class that uses hibernate, I have included all required jars to classpath
I have class that extend FragmentActivity in it I add fragment to layout as
I have class grades that I need to check if a specific grade is
I have class that looks like this: class A { public: class variables_map vm
I have class method that returns a list of employees that I can iterate
I have a method in a class that implements ValueChangeHandler<String> this class is initialised
I have class that has a property that is of type string[]. I need
I have class that is a DataContract and the member values are holding default
I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce 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.