Object sharing and dynamic instance creation
<p>I've a base class for business logic operations that is being inherited by my co-worker. This class expose a constructor which requires an <code>objectContext</code> as parameter. You can think of this base class as a component for atomic CRUD operations (all its select, insert, edit and delete method will always act on just one entity).</p>

<p>Then, I have a "super class" which its primary purpose is shared the <code>objectContext</code> between all the above base class in order to execute some business transaction and also it must provide any <code>baseClass</code> instance, if required.</p>

<p>So, I'm looking for to elegant way to "inject" superClass's <code>objectContext</code> into a <code>baseclass</code>: </p>

<pre><code>public BaseClass&lt;T&gt; where T : entity
{
    private ObjectContext _ctx;
    public BaseClass(ObjectContext ctx){ _ctx = ctx;}
    public virtual IList&lt;T&gt; Select(){..}
    public cirtual voind Insert(T entity){..}
    // other stuff 
}

public class SuperClass
{
    private ObjectContext _ctx = new...
    public BaseClass&lt;TEntity&gt; LoadBaseClass(TBase, TEntity) where TBase : BaseClass&lt;TEntity&gt;, where TEntity : class
    {
        BaseClass&lt;TEntity&gt; obj = Activator.CreateInstance(typeof(TBase), _ctx); // share objectContext
    }
    public int SaveAll(){return _ctx.SaveChanges();}
}
</code></pre>

<p>As you can see, my super class is able to return some <code>baseClass</code> instance through its type and it's just what I want. However, if some inherited class defines its own contructor with other parameter my <code>LoadBaseClass</code> method will fails.</p>

<p>I would find a clean solution in order to avoid any kind of possibility of error during instance creations from <code>LoadBaseClass</code> method. The only way I know is to define a private contructor, but by this way no-one will be able to inherit <code>baseclass</code> anymore..</p>
