Circular Class Library Dependency

  • Thread starter Thread starter Rafael Pivato
  • Start date Start date
Rafael,
The short answer is you cannot.

The long answer is use a Separated Interface Pattern:

http://www.martinfowler.com/eaaCatalog/separatedInterface.html

The first project defines a class and an interface that the class expects a
different class to implement. In the second project define a class that
implements the interface.

' Project 1

Public Interface INeedThis
Sub DoSomeWork()
End Interface

Public Class Class1

Public Sub DoSomething(ByVal needThis As INeedThis)
needThis.DoSomeWork()
End Sub

End Class

' Project 2
' references project 1

Public Class NeedThis
Implements INeedThis

Public Sub DoSomeWork() Implements INeedThis.DoSomeWork
End Sub

End Class

Notice that Project 2 references Project 1, but Project 1 does not reference
Project 2. If you want you can put the interface in its own project if you
have a number of interfaces.

Project 1 will need to be a class library. Project 2 can be a class library
or an Application.

Hope this helps
Jay
 
Rafael Pivato said:
How can I make two libraries with referencing each other ?

You can't. When you develop library 1 it needs to reference library 2, so
library 2 must be developed first. You can't develop library 2 first because
it needs to reference library 1.

You may consider a redesign by introducing a lower (common) layer referenced
by both libraries.
 
Back
Top