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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:21:45+00:00 2026-05-21T10:21:45+00:00

N.B., this is all C# 4.0 This might seem like an odd question, let

  • 0

N.B., this is all C# 4.0

This might seem like an odd question, let us say that all my business objects bind to a base class, let’s call it BaseObject, so I’ll have my classes inherit it like so:

public class CashRegister : BaseObject { }

Now most of the time I’m using, say, NHibernate on my projects. Some other projects come along and I’d like to use CouchDb. Rather than create a new BaseObject for each of these technologies, I’d like to somehow “bind” something like CouchDbObject to BaseObject … is this possible? Even better would be if I had an attribute and it would bind based on the attribute:

[CouchDb]
public class CashRegister : BaseObject { }

This might be crazy, but is it possible? Given the above example, I’d liek to do this:

var cashRegister = new CashRegister();
cashRegister.SomeGenericBaseObjectMethod();
cashRegister.SomeCouchDbSpecificMethod();

It seems that Ninject “contextual binding” does what I need, does it? I’m brainstorming right now, but it would be great if somewhere in my code I could do something like this to do the actual binding:

Bind<ICouchDbObject>.To<BaseObject>();

I would even be up for making BaseObject dynamic, or any other bleeding edge features that might make this possible. If this is not possible or a “don’t,” let me know! Trying to think outside the box.

  • 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-21T10:21:45+00:00Added an answer on May 21, 2026 at 10:21 am

    No, what you’re asking isn’t possible, for a couple of reasons.

    1. .NET doesn’t allow one class to directly inherit from multiple classes.
    2. The project needs to refer to the parent class’s library when it is compiled, so it can’t be assigned a new parent class at runtime.

    Usually when you run into a situation where you want to do what you’re describing, it’s because you’re using an architecture that doesn’t separate concerns well enough. I’m just guessing here, but you’ll probably be more flexible if you use an approach like this:

    public interface IBaseObject
    {
        int ObjectId {get;}
    }
    
    public class CashRegister : IBaseObject
    {
        int IBaseObject.ObjectId { get {return CashRegisterId;} }
    
        public int CashRegisterId {get;set;}
    }
    
    public class BaseObjectUtil
    {
        public void SomeGenericBaseObjectMethod(IBaseObject baseObject)
        {
            var objectId = baseObject.ObjectId;
            // Do something with the object ID.
        }
    }
    
    public class SomeUtility
    {
        private BaseObjectUtil _baseObjectUtil;
        public SomeUtility(BaseObjectUtil baseObjectUtil)
        {
            _baseObjectUtil = baseObjectUtil;
        }
    
        public void DoSomethingImportant(CashRegister register)
        {
            _baseObjectUtil.SomeGenericBaseObjectMethod(register);
        }
    }
    

    You’ll notice that so far we don’t have any code that relies on CouchDb. Now, say there’s another project that wants to be able to use the above project, but wants to be able to perform additional operations based on the CouchDb information. You might do something like this:

    public interface ICouchDbObject
    {
        string TableName {get;}
    }
    
    public class CouchDbUtil
    {
        public void SomeCouchDbSpecificMethod(ICouchDbObject couchDbObject)
        {
            var tableName = couchDbObject.TableName;
            // Do something with the table name.
        }
    }
    
    public class CouchDbCashRegister : CashRegister, ICouchDbObject
    {
        string ICouchDbObject.TableName {get{return "CashRegisters";}}
    }
    

    In this project, when you need a cash register, you would use a CouchDbCashRegister, which would allow you to call the CouchDb-specific methods on your CouchDbUtil class, while still allowing you to call the baseline utility methods in your BaseObjectUtil class.

    Furthermore, if you leverage a DI framework like Ninject to create your objects, you can actually make it so that all CashRegisters that get created in your second project are actually CouchDbCashRegisters.

    Bind<CashRegister>.To<CouchDbCashRegister>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is beyond both making sense and my control. That being said here is
I want to use a temp directory that will be unique to this build.
Let say I have the following desire, to simplify the IConvertible's to allow me
My question is about memory use and objects in actionscript 2. If I have
There doesn't seem to be any tried and true set of best practices to
I am writing a query to fetch results for all the values in a
I have a new web app that is packaged as a WAR as part
I have found this example on StackOverflow: var people = new List<Person> { new
I am attempting to pull some information from my tnsnames file using regex. I
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,

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.