Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

visual studio - Cannot add reference to project because of a circular dependency error

I created 2 dummy projects in my application and named them BAL and DAL. When I build them, they build successfully. If I add a reference to BAL to the DAL project, it added nicely. But while adding the DAL reference to the BAL project, I get the following error:

A reference to DAL could not be added. Adding this project as a reference would cause a circular dependency.

Can anyone help me to solve this error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's what you need to do:

  1. Right click on the DAL Project in the solution explorer and select Project dependencies in the context menu.

  2. You will now see a window that shows the project dependencies of the DAL Project. Make sure that BAL isn't checked.

Now you should be able to add your reference...

I hope this helps I've tried to keep it as simple and straight forward as possible.

Explanation:

Your DAL should not be able to access the BAL. Your code reference dependencies should be like this:

MVC project -> BAL -> DAL

The MVC project should reference the BAL, the BAL should reference the DAL. Set up your project like this. Make it work and then you will better understand why this setup is better.

Given:

  1. Data = raw numbers and strings
  2. Information = processed data into something meaningful

Cosider the following: The UI should get its information from the BAL which could be able to compose it's data based on the DAL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...