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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:14:49+00:00 2026-05-25T19:14:49+00:00

Suppose I have 3 classes to handle all database related requests: public class DB_A{}

  • 0

Suppose I have 3 classes to handle all database related requests:

public class DB_A{}
public class DB_B{}
public class DB_C{}

and I got 2 windows to interact with user:

window1.xaml;window1.xaml.cs;
window2.xaml;window2.xaml.cs

as window1 & window2 need to interact with database, they need to use functions from previous 3 classes, I created a class DataHandler:

public class DataHandler
{
    public DB_A a;
    public DB_B b;
    public DB_C c;

    public DataHandler()
    {
        a = new DB_A();
        b = new DB_B();
        c = new DB_C();
    }

    //some functions... ...
}

now the class DataHandler can handle all database related request, and now i need to pass a instant of DataHandler to both window1 and window2.

I tried to re-write the constructor for both window1 and window2 with parameter, but it does not allow me to do that. After google i know that WPF window form does not allow constructor with parameter.

Is there any way to pass my DataHandler to the two window form classes?

  • 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-25T19:14:50+00:00Added an answer on May 25, 2026 at 7:14 pm

    Make DataHandler a singleton, and let the window classes access it.

    public class DataHandler
    {
        //singleton instance
        static DataHandler _instance = new DataHandler ();
    
        public DataHandler Instance
        {
              get { return _instance; }
        }
    };
    

    Then,

    public partial class Window1 : Window
    {
       DataHandler _dataHandler;
    
       public Window1()
       {
            InitializeComponent();
    
            _dataHandler = DataHandler.Instance;
       }
    }
    

    Similarly, write other Window class.

    Or even better is, apply some variant of MVP pattern, most likely, MVVM. Read these articles:

    • Composite Guidance for WPF : MVVM vs MVP
    • WPF patterns : MVC, MVP or MVVM or…?
    • Model-View-Presenter Pattern
    • Model View Presenter
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have a collection of Foo classes: class Foo { public string Bar;
Suppose I have two classes: public class Student { public int Id {get; set;}
Suppose I have two classes deriving from a third abstract class: public abstract class
Suppose I have classes Foo and Bar as follow: public class Foo { public
suppose you have two (or more) classes with private member vectors: class A {
Suppose I have a class A which depends on 3 other classes X, Y
I am a NHibernate newbie. Suppose you have a Customer class like this public
Suppose I have an event KeyPress subscribed to by various classes. Assume that Class
Suppose I have two classes a base class and an inherited class as follows:
suppose I have two classes class A extends class B class A has its

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.