C#访问从&QUOT类;父项目"在"子项目"? [英] C# Accessing a class from a "parent project" in a "child project"?

查看:93
本文介绍了C#访问从&QUOT类;父项目"在"子项目"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个解决方案中的多个项目。我主要的项目 parent_project 和其他项目 child_project

Let's say I have multiple projects within a solution. I have the main project parent_project and another project child_project.

如何访问驻留在 parent_project child_project ?

我已经添加了一个参考 child_project parent_project 所以我不能一个参考 child_project 添加到 parent_parent ,因为它会创建一个循环依赖关系。

I have already added a Reference to child_project in parent_project so I can't add a Reference to parent_parent in child_project as it would create a circular dependency.

这可能吗?

推荐答案

如果您是项目之间共享逻辑,你需要隔离的依赖,并将其移动到共享位置(例如新项目),调整你的依赖,使您的核心逻辑住在一个核心结构域样的项目或捣烂您的项目组合在一起。

If you're sharing logic between projects, you need to isolate that dependency and move it to a shared location (new project for example), restructure your dependencies so that your core logic lives in a core domain-like project or mash your projects together.

后者是不是真的干净的解决方案。我建议考虑你自己的问题,真正试图回答为什么我需要一个循环引用?我如何重组,使我的依赖关系是否有意义?

The latter is not really the cleanest of solutions. I would recommend thinking about your own question and really try to answer "Why do I NEED a circular reference? How can I restructure so that my dependencies make sense?".

这篇关于C#访问从&QUOT类;父项目"在"子项目"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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