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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:11:47+00:00 2026-05-11T21:11:47+00:00

I am facing this strange problem while working with Generic Base Classes. I am

  • 0

I am facing this strange problem while working with Generic Base Classes. I am having three levels of base class hierarchy while the fourth level is the concrete class. Something as below.

// Level 0 (Root Base Class)    
public abstract class BusinessDataControllerBase<BDA> : IBusinessDataController
{
    protected BDA da;
    public BusinessDataControllerBase()
    {
    // Initialize the respective Data Access Layer passed by the concrete class
    BDA da = new BDA();
    }
}


// Level 1 (Second Level Base Class)
public abstract class BusinessRootDataControllerBase<BDA> : BusinessDataControllerBase<BDA>, IBusinessRootDataController
        where BDA : IBusinessDALController, new()
{
}

// Level 2 (Third Level Base Class)
public abstract class BusinessMasterRootDataControllerBase<BRC, BRD, BDA> : BusinessRootDataControllerBase<BDA>, IDisposable
        where BRC : IBusinessRootDataController 
        where BRD : IBusinessRootData
        where BDA : IBusinessDALController, new()
{
}

// Level 3 (Concrete Class)
public class UserController : BusinessMasterRootDataControllerBase<UserController, UserData, UsersDAL>
{
        # region Singleton implementation - Private Constructor, Static initialization
        private static readonly UserController instance = new UserController();
        public static UserController Instance
        {
            get { return instance; }
        }
        # endregion

        # region Constructor
        // --------------------------------------------------------------------------------
        //Private Constuctor
        private UserController()
        {
        }
        // --------------------------------------------------------------------------------

       private void DoLogin(string userName, string password)
        {
            DataSet dstUser = da.GetUser(userName);
            // Check user name
            // Check password
        }
}

What I want to achieve is absolute simple. I need the ‘da’ object to be instantiated at the top level base class. The concrete type ‘UsersDAL’ is supplied by the concrete class UserController and the correct type should be propagated till the top level base class (BusinessDataController) where it should be instantiated.

Now while I am debugging the BusinessDataController, I can see that the type (UsersDAL) is being propagated, a new UsersDAL() object is getting created in BusinessDataControllerBase() constructor but as soon as the code is coming out of the constructor in BusinessDataControllerBase, the ‘da’ member variables shows as ‘null’ and hence the DoLogin() process da.GetUser() is giving an error (object not instantiated).

But, if instead of instantiating ‘da’ in BusinessDataController, I create it in BusinessMasterRootData controller (at Level 2, i.e. the class just above the concrete class UserController), then everything is running fine and da.GetUser() works as expected.

I have tried to explore inheritance impacts of Generics (closed construction and open construction etc.) but could not find any deviations in my code. In design/compile time, I am not getting any error and getting all methods of UsersDAL with IntelliSense which possibly indicates that the type usage is correct.

Any idea where am I going wrong? I will have multiple base classes at the third level, i.e. the ‘BusinessMasterRootDataControllerBase’ level. So instantiating ‘da’ at the third level will make ‘da’ available in the concrete classes but will be redundant in all classes at that level and that is why I want to place it (‘da’) higher up. By the way, same observation is happening if I place the constructor code at the second level (i.e. BusinessRootDataControllerBase).

Another information to share is I am using the UserController (concrete class) as a Singleton class.

Any help is appreciated.

  • 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-11T21:11:48+00:00Added an answer on May 11, 2026 at 9:11 pm

    in

    protected BDA da;
    public BusinessDataControllerBase()
    {
      // Initialize the respective Data Access Layer passed by the concrete class
      BDA da = new BDA();
    }
    

    There are two items named ‘da’, you are assigning a new BDA() to a local variable that goes out of scope immediately. It probably should look like:

    protected BDA da;
    public BusinessDataControllerBase()
    {
      // Initialize the respective Data Access Layer passed by the concrete class
      da = new BDA();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How are you printing out the contents of your XDocument?… May 12, 2026 at 12:11 am
  • Editorial Team
    Editorial Team added an answer INSERT INTO `<table>` (column1, column2, ...) -- Not IDENTITY columns… May 12, 2026 at 12:11 am
  • Editorial Team
    Editorial Team added an answer What is a string? An array of characters. What is… May 12, 2026 at 12:11 am

Related Questions

I am facing a strange problem while sorting a list of strings with integer
I am facing strange issue on Windows CE: Running 3 EXEs 1)First exe doing
I am facing strange problem, Whenever I commented second if condition, it works in
I am facing this question in a new little project: The system to be

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.