add project reference to each other

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

in my vb.net solution, i have 3 project:
1. Main-this is the startup or the base of my window application.
2. Sales-this is the project that contains all the sales info
3. Product-this is the project contains all product info

in my Sales project, i added the reference of the Product to Sales project
because I need to shows the Product info in my Sales.
in the other hand, i also need to show the Sales in my Product. now the
problem comes, i can add Product reference to the Sales project, but, when i
try to add the Sales reference to my Product project, it show me that i
cannot add the reference because of circular dependency.

so, how do i soleve this??? i really need to add reference from and to each
another.
 
Create another project that will hold most of your code logic. This library
would then be referenced by any projects that need the support.
 
The Sales and Product projects not only having the business logic, but also
contains all the forms for display and data entry. Because these 2 projects
have a very close relationship, it may call or called by another project.

I cannot store all the forms/logic in single project. if store all in a
single project, it will be very difficult for maintenance.

and in my real situation, i totally have 14 projects in a solution, and
these 14 projects are related to each another, whereby each project may call
or/and called by other projects.

is there a way to overcome this? i think there is but i just dont know. if
not, there is no point for vs.net to allow us to create more than 1 project
in a single solution, right?

Please correct me if im not because im new in .net
Thanks
 
If you follow solid oo principals you should be able to (in fact it
would make the most sense to) separate solutions in several projects
without worrying about circular dependencies. The idea is to set up
your abstractions (at both the project level as well as class level) in
such a way that the projects are loosely coupled i.e., minimize the
knowledge that each project has about the others. The less each dll
knows about another the easier it will be to maintain and extend. For
example, rather than passing in an object from one project to another,
pass in parameters. That way the method isn't tightly coupled to the
object calling it. It sounds like you may want to consider refactoring
some key areas of your application with loose coupling in mind.

If you have common data structures that are used by many projects then
consider making them simple and in their own dll... That will get rid
of your circular dependency problem. However, read about dependency
inversion if you use this approach...
http://c2.com/cgi/wiki?PrinciplesOfObjectOrientedDesign
 
first of all, thanks for the replies.

just to make my question more simple and clearer. I have
Project A and Project B in a Solution1. in the Project A, i have a FormA and
in the Project B, i have a FormB. i added the Project B reference into
Project A, so that in my FormA, im able to call FormB from Project B. and
now, in my Project B, i need to use the FormA from Project A also, but, in
this case, im not able to add the Project A reference into Project B, which
make me cant call the FormA. I really dont want to create duplicate forms,
because i have a lot of projects which need to re-use each other forms from
different projects. any solution to overcome or by pass the circular
dependencies?
 
Alright, let's be blunt. No, you cannot overcome the circular reference
issue. Not to my knowledge. In the end, it is like "what came first, the
chicken or the egg?" This type of relationship cannot be defined.

I am not sure what you mean by duplicate forms. You might be thinking that
only EXEs can have forms. That is not try. Ultimately there is nothing
wrong with moving the forms (in their entirety) to some library DLL project.
This one library would then be shared by all your projects that need them.
 
In my Solution, i have 1 MainProject(which is winForm), and other projects
are classes which contains forms and user controls, eg. Project Account(Class
Library Project) and Project Issue(which is also a Class Library Project).

I added the 2 references of my Class Project, which are Account and Issue,
so that in my MainProject(the winForm), i can call both of the Forms in the
Account and Issue classes. This is no problem and can be done.

I also added Account Project reference to Issue Project, because i need to
call the forms, such as Account Profile, in the Account Project from Issue
Project, this is because i need to know the issue is tied to which account
and i want to able to link the account from issue. This can be done also.

At last, i also need to call the forms in Issue Project from Account
Project, this is because i want to know this account has how many issues and
what are they and able to link to the Issue Profile(forms in the Issue
Project). So, i have to add the Issue Project reference to the Account
Project, right? But now, i cant do this because of the circular dependencies!

If i just put all the forms/component... into a single project, this problem
wont happen but I want to separate and group only the related forms to it own
project, let say, Account Profile, Contact ... into the Account Project and
only the Issue related forms into the Issue Project. If i mix them all
together, this will be very messy and difficult to maintain the application.

In the other word, i want to call the forms in Account Project from Issue
Project and/or call the forms in Issue Project from Account Project.

Im so sorry for my poor english and really hope you all understand what im
talking about and my problem.

Thanks
 
Back
Top