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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:32:43+00:00 2026-05-24T22:32:43+00:00

I have a design question about constructors. After watching this video from google about

  • 0

I have a design question about constructors. After watching this video from google about “The Clean Code Talks”, he talked about the importance of the initializing classes and more in the constructor, and for better testing options. In my code for example i have a wcf service hosted on the iis in the service svc contructor we initialize the entire service.

 BService()
    {
        if (!m_DAL.Initilaze())
        {
            throw new Exception("Due to problems in the initialization B2BService is down");
        }

        m_sBadTransactionDir = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "BadTransaction";

        _address1 = new EndpointAddress(System.Configuration.ConfigurationManager.AppSettings["1Address"]);
        _address2 = new EndpointAddress(System.Configuration.ConfigurationManager.AppSettings["2Address"]);
        _address3 = new EndpointAddress(System.Configuration.ConfigurationManager.AppSettings["3Address"]);
        _address4 = new EndpointAddress(System.Configuration.ConfigurationManager.AppSettings["4Address"]);

        LoadSitesFromAdaptors();

        double interval1= Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["interval1"]);
        m_sentTransactionTimer.Interval = interval1;
        m_sentTransactionTimer.Elapsed += Foo1;
        m_sentTransactionTimer.Start();

        double interval2 = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["interval2"]);
        m_checkStatusTimer.Interval = interval2 ;
        m_checkStatusTimer.Elapsed += Foo2;
        m_checkStatusTimer.Start();

        double interval3= Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["interval3"]);
        m_adaptorsTimer.Interval = interval3;
        m_adaptorsTimer.Elapsed += Foo3;
        m_adaptorsTimer.Start();

.... and some more initialization code here


        Logger.Instance.Write("***************  Service is Up  ****************", "INFO");
    }

Do you guys know of better ways to initialize big classes ? make it easier to test
and generally your opinion on the matter ?

  • 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-24T22:32:44+00:00Added an answer on May 24, 2026 at 10:32 pm

    If this is the “main” class of the service, you may not want to unit test it. Or if it has functionality you want unit tested, you may want to move that functionality to separate class(es), which get the required config parameters (and just those) as constructor arguments. Thus they are easily unit testable.

    Alternatively, if you really really want to test this class, you could hide System.Configuration.ConfigurationManager behind a mockable interface, so that you can easily pass in whatever parameters you need for your unit tests. But in general, you will almost always have some high level class(es) in your apps which just initialize the whole stuff, load config parameters from command line / config files / registry / DB / whatever, and pass these around to the other classes which do the real work. In a well designed app, such classes have this single responsibility, and it is validated by integration/system tests rather than unit tests.

    On a smaller scale, the code above contains duplication in these segments:

        double interval1= Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["interval1"]);
        m_sentTransactionTimer.Interval = interval1;
        m_sentTransactionTimer.Elapsed += Foo1;
        m_sentTransactionTimer.Start();
    

    These could be easily extracted into a single method with parameters.

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

Sidebar

Related Questions

I have a question about best practices with the Module Design Pattern. The code
This is a question about style and design rather than syntax. I have domain
I have a question about design winforms. Should I use, or not, group boxes
I have posted a question about multilanguage database design here, [] What are best
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor()
This is a general design question about how to make a web application that
I have a question about usability/design. I currently am using some JQuery to hide/show
I have a general question about the design of JavaScript Libraries. I am trying
I have a design question about the use of Hibernate annotations and DAO pattern.
I am currently building a multiplayer system, and I have a design question about

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.