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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:12:58+00:00 2026-05-29T19:12:58+00:00

If one uses property injection how do you set properties on that type? For

  • 0

If one uses property injection how do you set properties on that type? For example

public class MyClass
{
   public ITimer MyTimer {get;set;}
}

We can use DI to resolve ITimer but how/where do we define property values for ITimer, for example, if you want to set the Interval property where does this happen?

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-05-29T19:13:00+00:00Added an answer on May 29, 2026 at 7:13 pm

    Please clarify …what do you mean by ‘if you want to set the Interval property where does this happen?’ If you are looking for when to set properties for ITimer, I prefer using a method for better readability and maintenance:

    public class MyClass {
        private ITimer timer;
    
        public ITimer Timer {
            get { return timer; }
            set { SetDefaultTimer(value); }
        }
    
        private void SetDefaultTimer(ITimer timer) {
            timer.Interval = 1000;
            // other default properties
    
            // assign
            this.timer = timer;
        }
    }
    

    I don’t believe this will stop someone from altering the interval or other properties on the Timer. I don’t know if that is your intent.

    Update:
    Depending on your ITimer interface, you could completely hide the Interval property which means that the interval could not be altered because of encapsulation. Exposing the interval property through encapsulation requires something like the following:

    public interface ITimer {
        int Interval {get; set;}
    }
    

    …exposes a way to set an interval value – e.g.:

    public class MyTimer : ITimer {
        Timer timer;
    
        // implement ITimer member
        public int Interval {
            get { return timer.Interval; }
            set { timer.Interval = value; }
        }
    }
    

    If the interface did not define the property, there is no way to access the encapsulated timer properties outside of your controlled API (except maybe by reflection …)

    Hope that helps.

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

Sidebar

Related Questions

I have a class that uses the __set magic method. One of the properties
Let's say you've inherited a C# codebase that uses one class with 200 static
Let's say I have a class with a public property used for property injection,
I have a base class ReportElement which has type property: public abstract class ReportElement
I understand one uses the bless keyword in Perl inside a class's new method:
How to use such functionality of windows-7 with WPF (one that uses Itunes -
We have an app that uses simple one way binding with a GridView to
Getting attributes using minidom in Python, one uses the attributes property. e.g. node.attributes[id].value So
I have a WPF app that uses an Entity Framework Model. One of the
I have a class that has some properties. And I want something that calculates

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.