Circular References...

T

Tom

Let's assume I have the following libraries:

MainLib (DLL)
MyControl (.NET user control)

Now MyControl needs to call MainLib, so I have a reference to MainLib
in MyControl. Let's then assume that I want to put a new form
(MyNewForm) in MainLib, but this form requires MyControl (i.e. I will
drop a copy if MyControl onto the MyNewForm). This would require me to
put a reference to MyControl in MainLib. Now I have MainLib referencing
MyControl, and MyControl referencing Mainlib!

Would this kind of circular reference even work? My problem is in what
order would something like this be compiled? I would think I would
first have to compile MyControl, then MainLib; but as soon as I
recompile MainLib the reference to MainLib in MyControl is now not
'current'...

Ugh, it hurts my head just thinking about this... I suppose the better
way would just be to make MyNewForm into it's own DLL, but was
wondering if something like the above scenario would work or is it even
recommended?

Thanks.

Tom
 
B

Brian Gideon

Tom,

It is definitely not recommended. You should put MyNewForm into
another assembly or in the same assembly that contains MyControl.

Brian
 
P

Phill. W

Tom said:
MyControl needs to call MainLib, so I have a reference to MainLib
in MyControl. Let's then assume that I want to put a new form
(MyNewForm) in MainLib, but this form requires MyControl
(i.e. I will drop a copy if MyControl onto the MyNewForm).
This would require me to put a reference to MyControl in MainLib. .. . .
Would this kind of circular reference even work?

No. Circular references aren't supported in VB.Net.

Look at Interfaces. Use these to define:
(a) what the Library looks like to /any/ control,
(b) what /every/ control looks like to the Library,
(c) (possibly even) what each control looks like to /another/ control.

Something like

Interface ILibrary
Public Sub Method1()
Public Sub Method2()
End Interface

Interface ICustomControl
Public Show Show()
Public Show ShowDialog()
End Interface

Place of all these Interfaces into a third, shared library that is
referenced by both of the other two. Now, your circular references
have been extracted into this third assembly - so no problem there -
and each object knows "enough" about the others (as defined in the
Interfaces) to get on with whatever they all need to do.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top