简体   繁体   English

正确组织C#中项目之间的依赖关系

[英]Right organization of dependencies between projects in C#

Good afternoon. 下午好。 How should I organize the following structure using C#, the .NET platform, and Visual Studio projects? 我应该如何使用C#,.NET平台和Visual Studio项目组织以下结构?

The solution should contains several projects (dll or winmd as result). 解决方案应包含多个项目(结果为dll或winmd)。 FrameworkB and FrameworkC depend on FrameworkA . FrameworkBFrameworkC依赖于FrameworkA ClassA from FrameworkA , ClassD from FrameworkB , and ClassF from FrameworkC are public and visible to framework users; ClassAFrameworkAClassDFrameworkB ,并ClassFFrameworkC是公开的,可见的框架的用户; other classes are not accessible to them (there is no possibility to create objects or call a methods). 他们无法访问其他类(不可能创建对象或调用方法)。 In this case, from ClassE and ClassG we should be able to use the methods from ClassB and ClassC . 在这种情况下,从ClassEClassG我们应该能够使用ClassBClassC的方法。

So: 所以:

  • FrameworkA , FrameworkB , and FrameworkC should be a different .dll or .winmd files (But B and C depend on A ). FrameworkAFrameworkBFrameworkC应该是不同的.dll.winmd文件(但BC依赖于A )。
  • ClassB , ClassC , ClassE , and ClassG should be private to framework end-users, but B and C should be visible and used by E and G . ClassBClassCClassEClassG应该是框架最终用户的私有,但BC应该是可见的并由EG
Solution
    FrameworkA
        ClassA
        ClassB
        ClassC
    FrameworkB
        ClassD
        ClassE
    FrameworkC
        ClassF
        ClassG

As per this answer , you could use an InternalsVisibleTo attribute and use Internal access modifier on classes B and C. 根据这个答案 ,您可以使用InternalsVisibleTo属性并在类B和C上使用内部访问修饰符。

That way, classes from the first assembly can be used by other two, but not by client written software. 这样,第一个程序集中的类可以由其他两个使用,但不能由客户端编写的软件使用。

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

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