circular dependency

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    circular dependency

    I ran into a problem with circular dependencies. My code
    looks somthing like:

    using B
    namespace A
    {
    class formA
    {
    void foo()
    {
    formB B = new formB();
    B.show();
    }

    void changeMenu()
    {
    ...
    }
    }
    }

    --------------------------------------------------------

    //using A // this would create a circular dependency
    namespace B
    {
    class formB
    {
    formA A;
    void formB()
    {
    A = (formA)this.par entForm;
    A.changeMenu(); //formA is the parent MDI
    //form and I want to change
    //the menu of formA when
    //formB gets displayed inside
    //it.
    }
    }
    }

    The way it's written, the .cs file that contains
    namespace B won't compile because there is no reference
    to namespace A. But I can't add a reference because it
    would create a circular dependency. Is there anything I
    can do without putting these into the same project? Does
    C# have something similar to forward references in C++?
    This has been driving crazy so any suggestions would be
    most geatly appreciated. Thank you for your reply.

    Mike

  • Darrin J Olson

    #2
    Re: circular dependency

    My suggestion would be to create a custom event with a custom delegate and
    event parameters. Throw the event when you need to, and catch it with your
    parent form (MDI form). The event could then carry the information you need
    to change the menu, and could be thrown whenever you need it.

    -Darrin


    "Mike" <mikebiros@hotm ail.com> wrote in message
    news:036d01c3ab e7$a32b60f0$a10 1280a@phx.gbl.. .[color=blue]
    > I ran into a problem with circular dependencies. My code
    > looks somthing like:
    >
    > using B
    > namespace A
    > {
    > class formA
    > {
    > void foo()
    > {
    > formB B = new formB();
    > B.show();
    > }
    >
    > void changeMenu()
    > {
    > ...
    > }
    > }
    > }
    >
    > --------------------------------------------------------
    >
    > //using A // this would create a circular dependency
    > namespace B
    > {
    > class formB
    > {
    > formA A;
    > void formB()
    > {
    > A = (formA)this.par entForm;
    > A.changeMenu(); //formA is the parent MDI
    > //form and I want to change
    > //the menu of formA when
    > //formB gets displayed inside
    > //it.
    > }
    > }
    > }
    >
    > The way it's written, the .cs file that contains
    > namespace B won't compile because there is no reference
    > to namespace A. But I can't add a reference because it
    > would create a circular dependency. Is there anything I
    > can do without putting these into the same project? Does
    > C# have something similar to forward references in C++?
    > This has been driving crazy so any suggestions would be
    > most geatly appreciated. Thank you for your reply.
    >
    > Mike
    >[/color]


    Comment

    • Grant Richins [MS]

      #3
      Re: circular dependency

      You could create an interface that formA uses. Then both projects would
      reference the interface, and formB would not reference formA.

      --
      --Grant
      This posting is provided "AS IS" with no warranties, and confers no rights.


      "Mike" <mikebiros@hotm ail.com> wrote in message
      news:036d01c3ab e7$a32b60f0$a10 1280a@phx.gbl.. .[color=blue]
      > I ran into a problem with circular dependencies. My code
      > looks somthing like:
      >
      > using B
      > namespace A
      > {
      > class formA
      > {
      > void foo()
      > {
      > formB B = new formB();
      > B.show();
      > }
      >
      > void changeMenu()
      > {
      > ...
      > }
      > }
      > }
      >
      > --------------------------------------------------------
      >
      > //using A // this would create a circular dependency
      > namespace B
      > {
      > class formB
      > {
      > formA A;
      > void formB()
      > {
      > A = (formA)this.par entForm;
      > A.changeMenu(); //formA is the parent MDI
      > //form and I want to change
      > //the menu of formA when
      > //formB gets displayed inside
      > //it.
      > }
      > }
      > }
      >
      > The way it's written, the .cs file that contains
      > namespace B won't compile because there is no reference
      > to namespace A. But I can't add a reference because it
      > would create a circular dependency. Is there anything I
      > can do without putting these into the same project? Does
      > C# have something similar to forward references in C++?
      > This has been driving crazy so any suggestions would be
      > most geatly appreciated. Thank you for your reply.
      >
      > Mike
      >[/color]


      Comment

      Working...