CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2006
    Posts
    82

    Where to instantiate wrapper class?

    I'm using VC# 2010 Express to create a multi-form application, for dot Net 4.
    I created several DLLs in order to separate functional implementations - eg file IO, data manipulation, etc. Both the form classes and the DLL classes have C# interfaces, to make out-calls to the DLLs. I opted to implement all the interfaces and instantiate the DLL's in one wrapper class, IFClass. But now the problem is where to instantiate the IFClass so that a form can access the IFClass members?

    I tried instantiating the wrapper class in the main form class, but was refused - I get a message that says it would cause circular references.

    So...where do I instantiate IFClass?

    I don't really want to make the DLLs static - had hoped to do it all with dynamic code.

    Here is some code:
    Code:
    //Mainform.cs
    using System;
    using System.Windows.Forms;
    //Can't reference IFClass here: Cicular reference.
    namespace WrapperClassTest1
    {
    	public partial class Mainform : Form
    	{
    		public Mainform()
    		{	InitializeComponent();	}
    //The button on the main form would open Subform1
    		private void btnGoSubform1_Click(object sender, EventArgs e)
    		{	/*...*/ }
    	}
    }
    --------
    //Subform1.cs
    using System;
    using System.Windows.Forms;
    namespace WrapperClassTest1
    {
    	public interface ISubform1
    	{ 	void OutfromSubform1(); }
    	public partial class Subform1 : Form
    	{
    		public Subform1()
    		{	InitializeComponent();	}
    	}
    }
    ----------
    //ClassA.cs
    namespace nsClassA
    {
    	public interface IClassA
    	{ 	void OutfromClassA();	}
    	public class ClassA
    	{	}
    }
    ----------------
    //IFClass.cs
    using System;
    using WrapperClassTest1;
    using nsClassA;
    namespace nsIFClass
    {
    	public class IFClass: IClassA, ISubform1
    	{
    		//ClassA CA = new ClassA();
    		public void OutfromClassA()
    		{ }
    		public void OutfromSubform1()
    		{ }
    	}
    }
    Last edited by Lou Arnold; May 6th, 2011 at 07:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured