简体   繁体   English

如何在不调用DLL作为C#引用的情况下从一个项目调用另一个项目的类?

[英]How to call a class from a project to another project without call the DLL as reference in C#?

I have three parts of a project, one is Core(bussiness) project, one is webproject and the last is the test project. 我有一个项目的三个部分,一个是核心(商务)项目,一个是web项目,最后一个是测试项目。

I want to call some classes that I saved in one folder from core project to webproject without calling the dll of the core project. 我想调用一些我从核心项目保存到Web项目的文件夹中的类,而不调用核心项目的dll。 Since core project is already refereed into the webproject. 由于核心项目已被引用到Web项目中。 So it will call the cycling if the references and not allow me to do that. 因此,如果有引用但不允许我这样做,它将调用循环。

How I can use classes from core project to web project without call the DLL? 如何在不调用DLL的情况下使用从核心项目到Web项目的类? I Have already tried 'using', The code is following. 我已经尝试过“使用”,下面的代码。 It's not working for me. 它对我不起作用。

using BlogEngine.Core.API.PageML; // I need to call all classes from this folder
using BlogPage = BlogEngine.Core.API.PageML;
namespace admin.Settings
{
 public partial class DownloadInsertPage : System.Web.UI.Page{
  protected void BtnPageMLInsertClick(object sender, EventArgs e)
  {
   var reader = new PageReaders(); // the class, I want to call from the core project
  }
}

Thanks 谢谢

Your question is unclear ("since web project is already refereed into the webproject" for example) but you should really make the web project have a reference to the core project, but not the other way round. 您的问题尚不清楚(例如,“因为Web项目已被引用到Web项目中”),但是您应该确实使Web项目具有对核心项目的引用,而不是相反。 The core business logic shouldn't know about your web "view" onto it, but the web project should absolutely know about the core business classes. 核心业务逻辑不应该了解您的Web“视图”,但是Web项目应该绝对了解核心业务类。

If you have classes in the web project which you're currently referring to from the core project, you should probably move them to the core project - or to a third project which both of the other projects refer to, if they don't logically belong in the core project itself. 如果您当前从核心项目中引用的Web项目中有类,则可能应该将它们移至核心项目-或移至其他两个项目均引用的第三个项目(如果它们在逻辑上不是逻辑上的)属于核心项目本身。

Your model may benefit from contract interfaces - that would help you redesign your current model in order to avoid circular references. 您的模型可能会受益于合同接口-这将帮助您重新设计当前模型,以避免循环引用。 Here's some posts about this: 这是有关此的一些帖子:

a design to avoid circular reference in this scenario 在这种情况下避免循环引用的设计

Resolving Circular References (C#) 解决循环引用(C#)

Now, I may have misunderstood your question, and you'd rather benefit more from learning about add-on models. 现在,我可能误解了您的问题,并且您希望从学习附加模型中受益更多。 In that case, this post may be of some help: 在这种情况下,这篇文章可能会有所帮助:

C# Plugin Architecture with interfaces share between plugins 具有插件之间共享接口的C#插件体系结构

You cannot. 你不能。

If you need these classes to be accessible in both assembly, you should create a third one that would be referenced by both of them although this should be reserved to cross-cutting concerns only (eg logging logic). 如果您需要在两个程序集中都可以访问这些类,则应创建第三个类,这两个类都可以引用这三个类,尽管这仅应保留给跨领域的关注点(例如,记录逻辑)。

Thank you guys for your valuable comments.. I want to share, what was the problem and how I resolved it. 谢谢大家的宝贵意见。我想分享一下,问题出在哪里,我如何解决。

I build the core project after created some classes into the PageML folder and build it without calling this folder into the web project. 在将一些类创建到PageML文件夹后,我将构建核心项目,并在不将该文件夹调用到Web项目的情况下进行构建。 and update the reference(dll) of core project in the webproject. 并更新Web项目中核心项目的reference(dll)。 and it's working for me. 它为我工作。

Thank you All 谢谢你们

Keep clam and do coding. 保持蛤并进行编码。

:) have a nice time :)玩得开心

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM