CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jul 2002
    Location
    India
    Posts
    505

    Circular dependencies

    Hi Gurus,

    My post below is quite long, but I could not find any way to explain my problem without giving some background. Any comments would be most valuable.



    I have a windows forms application, that has 3 projects.

    1) Windowsapplication - This holds the MDI parent form
    2) ClassLibrary1 - This holds various forms that are opened as child forms within the MDI
    3) BaseLibrary - this holds the baseclasses for forms in ClassLibrary1. (FrmBase and FrmModalBase)

    So at this point, WindowsApplication has a reference to ClassLibrary1 and BaseLibrary
    and
    ClassLibrary1 has a reference to BaseLibrary and all is well in my app.


    Now, I have a requirement for all forms in ClassLibrary1 that inherit from FrmBase to have a button which when clicked will show
    a modal form displaying some data. Since the data on the form is going to be the same irrespective of which form I call it from, I
    decide to put this button on Frmbase. Note that the modal form that is to be called is in ClassLibrary1.

    My above solution to put the button on FrmChildBase cannot be implemented because this would need BaseLibrary to have a reference
    to ClassLibrary1, which would create a circular reference. I tried this and VS.net gave me the following error message -
    "A reference to project "ClassLibrary1" could not be added. Adding this project as a reference would cause a circular dependency"

    I thought that was the end of this idea and that I would have to come up with a different way to do this, when another developer
    came up with a way to solve this. Here is what he does:

    1) Get the reference path for ClassLibrary1 from the WindowsApplication project. Let say this is the path -
    "C:\MiscTests\WindowsApplication\ClassLibrary1\obj\Debug\ClassLibrary1.dll"

    2) Now in BaseLibrary right click to add reference, click browse and type in the file path above and click OK

    This way, vs.net does not complain about a circular reference. I tried this and it works as desired.

    Now my question is a) why does this work, when it really is a circular reference. b)It my work now, but will it cause some other problem - Say a memory leak?

    I have attached a stripped down example. It has no real functionality, but demonstrates the app working with the circular refernce. You will need to create a folder called misctest under c: and extract the zip there, since the reference path is hardcoded.

    Thanks
    Satish
    Attached Files Attached Files

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