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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:04:18+00:00 2026-05-26T18:04:18+00:00

I have a class which has been steadily growing over time. It’s called LayoutManager

  • 0

I have a class which has been steadily growing over time. It’s called LayoutManager.

It started as a way for me to keep track of which dynamically created controls were on my page. So, for instance, I have this:

public CormantRadDockZone()
{
    ID = String.Format("RadDockZone_{0}", Guid.NewGuid().ToString().Replace('-', 'a'));
    MinHeight = Unit.Percentage(100);
    BorderWidth = 0;
    HighlightedCssClass = "zoneDropOk";
    CssClass = "rightRoundedCorners";
    LayoutManager.Instance.RegisteredDockZones.Add(this);
}

In this way, during the beginning stages of the Page Lifecycle, controls would be re-created and they would add themselves to their respective control’s list.

A while later I found myself passing the ‘Page’ object between methods. This was for the sole purpose of being able to access controls found on Page. I thought to myself — well, I already have a Layout Manager, I’ll just treat the static controls in the same way.

As such, my Page_Init method now looks like this mess:

protected void Page_Init(object sender, EventArgs e)
{
    SessionRepository.Instance.EnsureAuthorized();

    LayoutManager.Instance.RegisteredPanes.Clear();
    LayoutManager.Instance.RegisteredDocks.Clear();
    LayoutManager.Instance.RegisteredDockZones.Clear();
    LayoutManager.Instance.RegisteredSplitters.Clear();
    LayoutManager.Instance.RegisteredSplitBars.Clear();
    LayoutManager.Instance.RegisteredPageViews.Clear();

    LayoutManager.Instance.CheckBox1 = CheckBox1;
    LayoutManager.Instance.CheckBox4 = CheckBox4;

    LayoutManager.Instance.StartEditButton = StartEditButton;
    LayoutManager.Instance.FinishEditButton = FinishEditButton;

    LayoutManager.Instance.RadNumericTextBox1 = RadNumericTextBox1;
    LayoutManager.Instance.RadNumericTextBox2 = RadNumericTextBox2;

    LayoutManager.Instance.LeftPane = LeftPane;
    LayoutManager.Instance.DashboardUpdatePanel = DashboardUpdatePanel;

    LayoutManager.Instance.CustomReportsContainer = CustomReportsContainer;
    LayoutManager.Instance.HistoricalReportsContainer = HistoricalReportsContainer;
    RegenerationManager.Instance.RegenerateReportMenu();

    LayoutManager.Instance.MultiPage = DashboardMultiPage;
    LayoutManager.Instance.MultiPageUpdatePanel = MultiPageUpdatePanel;
    LayoutManager.Instance.TabStrip = DashboardTabStrip;

    RegenerationManager.Instance.RegenerateTabs(DashboardTabStrip);
    RegenerationManager.Instance.RegeneratePageViews();

    LayoutManager.Instance.Timer = RefreshAndCycleTimer;
    LayoutManager.Instance.Timer.TimerEvent += DashboardTabStrip.DoTimerCycleTick;

    RegenerationManager.Instance.RegeneratePageState();
}

I’m looking at that and saying no, no, no. That is all wrong. Yet, there are controls on my page which are very dependent on each other, but do not have access to each other. This is what seems to make this so necessary.

I think a good example of this in practice would be using UpdatePanels. So, for instance, DashboardUpdatePanel is being given to the LayoutManager. There are controls on the page which, conditionally, should cause the entire contents of the dashboard to update.

Now, in my eyes, I believe I have two options:

  1. Inside the object wanting to call UpdatePanel.Update(), I recurse up through parent objects, checking type and ID until I find the appropriate UpdatePanel.
  2. I ask LayoutManager for the UpdatePanel.

Clearly the second one sounds cleaner in this scenario… but I find myself using that same logic in many instances. This has resulted in a manager class which looks like this:

public class LayoutManager
{
    private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

    private static readonly LayoutManager _instance = new LayoutManager();
    private LayoutManager() { }

    public static LayoutManager Instance
    {
        get { return _instance; }
    }

    private IList<CormantRadDock> _registeredDocks;
    private IList<CormantRadDockZone> _registeredDockZones;
    private IList<CormantRadPane> _registeredPanes;
    private IList<CormantRadSplitter> _registeredSplitters;
    private IList<CormantRadSplitBar> _registeredSplitBars; 
    private Dictionary<string, StyledUpdatePanel> _registeredUpdatePanels;
    private IList<CormantRadPageView> _registeredPageViews;

    public RadMultiPage MultiPage { get; set; }
    public CormantTimer Timer { get; set; }
    public CormantRadListBox HistoricalReportsContainer { get; set; }
    public CormantRadListBox CustomReportsContainer { get; set; }
    public StyledUpdatePanel MultiPageUpdatePanel { get; set; }
    public CormantRadTabStrip TabStrip { get; set; }
    public RadPane LeftPane { get; set; }
    public StyledUpdatePanel DashboardUpdatePanel { get; set; }
    public RadButton ToggleEditButton { get; set; }

    public CheckBox CheckBox1 { get; set; }
    public CheckBox CheckBox4 { get; set; }
    public RadNumericTextBox RadNumericTextBox1 { get; set; }
    public RadNumericTextBox RadNumericTextBox2 { get; set; }

    public RadButton StartEditButton { get; set; }
    public RadButton FinishEditButton { get; set; }

    public IList<CormantRadDock> RegisteredDocks
    {
        get
        {
            if (Equals(_registeredDocks, null))
            {
                _registeredDocks = new List<CormantRadDock>();
            }

            return _registeredDocks;
        }
    }

    public IList<CormantRadDockZone> RegisteredDockZones
    {
        get
        {
            if (Equals(_registeredDockZones, null))
            {
                _registeredDockZones = new List<CormantRadDockZone>();
            }

            return _registeredDockZones;
        }
    }

    public IList<CormantRadPane> RegisteredPanes
    {
        get
        {
            if (Equals(_registeredPanes, null))
            {
                _registeredPanes = new List<CormantRadPane>();
            }

            return _registeredPanes;
        }
    }

    public IList<CormantRadSplitter> RegisteredSplitters
    {
        get
        {
            if (Equals(_registeredSplitters, null))
            {
                _registeredSplitters = new List<CormantRadSplitter>();
            }

            return _registeredSplitters;
        }
    }

    public IList<CormantRadSplitBar> RegisteredSplitBars
    {
        get
        {
            if (Equals(_registeredSplitBars, null))
            {
                _registeredSplitBars = new List<CormantRadSplitBar>();
            }

            return _registeredSplitBars;
        }
    }

    public Dictionary<string, StyledUpdatePanel> RegisteredUpdatePanels
    {
        get
        {
            if( Equals( _registeredUpdatePanels, null))
            {
                _registeredUpdatePanels = new Dictionary<string, StyledUpdatePanel>();
            }

            return _registeredUpdatePanels;
        }
    }

    public IList<CormantRadPageView> RegisteredPageViews
    {
        get
        {
            if (Equals(_registeredPageViews, null))
            {
                _registeredPageViews = new List<CormantRadPageView>();
            }

            return _registeredPageViews;
        }
    }

    public StyledUpdatePanel GetBaseUpdatePanel()
    {
        string key = MultiPage.PageViews.Cast<CormantRadPageView>().Where(pageView => pageView.Selected).First().ID;
        return RegisteredUpdatePanels[key];
    }

    public CormantRadDockZone GetDockZoneByID(string dockZoneID)
    {
        CormantRadDockZone dockZone = RegisteredDockZones.Where(registeredZone => dockZoneID.Contains(registeredZone.ID)).FirstOrDefault();

        if (Equals(dockZone, null))
        {
            _logger.ErrorFormat("Did not find dockZone: {0}", dockZoneID);
        }
        else
        {
            _logger.DebugFormat("Found dockZone: {0}", dockZoneID);
        }

        return dockZone;
    }

    public CormantRadPane GetPaneByID(string paneID)
    {
        CormantRadPane pane = RegisteredPanes.Where(registeredZone => paneID.Contains(registeredZone.ID)).FirstOrDefault();

        if (Equals(pane, null))
        {
            _logger.ErrorFormat("Did not find pane: {0}", paneID);
        }
        else
        {
            _logger.DebugFormat("Found pane: {0}", paneID);
        }

        return pane;
    }

    public CormantRadDock GetDockByID(string dockID)
    {
        CormantRadDock dock = RegisteredDocks.Where(registeredZone => dockID.Contains(registeredZone.ID)).FirstOrDefault();

        if (Equals(dock, null))
        {
            _logger.ErrorFormat("Did not find dock: {0}", dockID);
        }
        else
        {
            _logger.DebugFormat("Found dock: {0}", dockID);
        }

        return dock;
    }
}

Am I on a bad path? What steps are generally taken at this point?

EDIT1: I have decided to start down the path of improvement by finding the controls which are least-integrated into LayoutManager and finding ways of breaking them down into separate objects. So, for instance, instead of assigning the HistoricalReportsContainer and CustomReportsContainer objects to LayoutManager (which is then used in RegenerationManager.RegenerateReportMenu) I have moved the code to RadListBox “Load” event. There, I check the ID of the control which is loading and react accordingly. A strong first improvement, and has removed 2 controls and a method from LayoutManager!

  • 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-26T18:04:18+00:00Added an answer on May 26, 2026 at 6:04 pm

    Inversion of control is a general approach that people use for such problems. Your dependencies should not be stored in the one Jack-Bauer-kind-of-style class, but rather be injected, for example via constructor. Take a look at the IoC containers, such as Castle Windsor, Unity, NInject or any other.

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

Sidebar

Related Questions

Consider the code below (which has been simplified). I have a service class that
My situation is essentially this: I have a class called Foo which has dependencies
I have a domain class called Flight that represents a flight that has been
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a class which has many small functions. By small functions, I mean
I have an class which has a enum property and a boolean property, based
I have a class which has a function to retrieve children elements from a
I have a class which has a private attribute which is a reference to
I have a class which has a private attribute vector rectVec; class A {
I have a class which has two HashSet<String> collections as private members. Other classes

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.