ASP.NET MVC:如何避免2个项目之间的循环引用 [英] ASP.NET MVC: How to avoid circular reference between 2 projects

查看:42
本文介绍了ASP.NET MVC:如何避免2个项目之间的循环引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序至少有两个项目,OrganizationMangement和ContactManagement.以前,我引用ContactManagement是因为我需要使用OrganizationManagement中的一个类.现在,我需要做相反的事情,但出现以下错误"无法引用OrganizationManagement ...以避免循环引用."

My application has at least 2 projects, the OrganizationMangement and the ContactManagement. Previously, I referenced ContactManagement because I need to work with a class located in the OrganizationManagement. Now I need to do the reverse but I'm getting the following error "Cannot reference OrganizationManagement ... to avoid circular reference."

我想这个错误是有道理的.但是,我该如何避免呢?我的意思是我只需要那些类就可以将数据从一个项目传输到另一个项目.

I guess the error makes sense. But, how can I avoid that? I mean I need those classes just to transfert data from one project to another.

为解决此问题,我将类复制到另一个项目中的文件夹中并尝试了

To solve the problem, I copied the class to a folder located in the other project and tried this

var contact = (Contact)TempData["contact"];

现在,我遇到此错误:无法将 ContactManagement.Contact 隐式转换为 OrganizationManagement.Contact ... ,存在显式转换...

Now, I'm getting this error: Cannot convert implicitly ContactManagement.Contact to OrganizationManagement.Contact... an explicit conversion exists...

感谢您的帮助

推荐答案

也许您应该将所有与域相关的通用类重构为自己的新项目,然后其他项目才能引用该新项目.

Maybe you should refactor all the common domain-related classes to their own new project that can then be referenced by the other projects.

另一方面,通过定义结构上相同但名称仅不同的类之间的显式转换,我可以为您遇到的错误提出一个非常糟糕的解决方法.但是请不要这样做.将所有域内容(即与联系人相关的类,如Contact,Person,Organization,Customer等)放入其自己的项目,并从需要这些类的项目中引用.

On the other hand I could suggest a very bad workaround for the error you encounter by defining an explicit conversion between the structurally identical classes that only differ in name. But please don't do so. Put all the domain stuff (i.e. entitiy-related classes like Contact, Person, Organization, Customer etc.) to its own project and reference this from the projects that need the classes.

这篇关于ASP.NET MVC:如何避免2个项目之间的循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆