Domanda

Using Visual Studio 2008:

Within the Solution there is a main project (Project1), within the same solution there are other projects (these projects are Excel 2007 Workbook templates). These other projects need to reference classes and objects within Project1, and Project1 needs to be able to access the Workbook projects.

What I currently have now is the other projects are set to be dependent upon Project1 and a reference is added to the other projects for Project1.

Is this the correct way to do what I am trying to accomplish or is there another way?

È stato utile?

Soluzione

You cannot have two projects depend on each other (this is entirely logical; which project should be built first?). You should move the parts in Project1 that is needed both by Project1 and the Workbook projects into a separate project, that can be referenced both by Project1 and the Workbook projects.


Update
There are several different ways of handling this situation, and without knowing the details of your application I can't give any specific solution. But one way is to use dependency injection. Instead of having the Workbook project have a hard-wired dependency on the code in Project1, you can extract an interface for this functionality. This interface is placed in another project that can be referenced both by Project1 and the Workbook project.

Then I assume that Project1 will create instances of types in the Workbook project. This means that you should alter the constructors of these types to have a parameter if this interface type. Project1 will contain an implementation of the interface that it will pass to the Workbook project types when creating them.

That way the Workbook project code can use code from Project1 without having a reference to it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top