简体   繁体   English

.NET Core 1.1允许访问间接依赖关系类型

[英].NET Core 1.1 allowing access to indirect dependencies types

I created a new .NET Core 1.1 solution and noticed an odd behavior: if I create multiple projects in the solution and chain-reference them, I'm able to freely access types located in a dependency of a dependency, any level down. 我创建了一个新的.NET Core 1.1解决方案,并注意到一个奇怪的行为:如果我在该解决方案中创建多个项目并对其进行链式引用,则可以自由访问位于某个依赖项依赖项中的类型,无论其级别如何。

This is an example: 这是一个例子:

在此处输入图片说明

We have a Sandbox solution, a Baz class library project, a Bar class library project referencing Baz and a Foo console app project referencing Bar . 我们有一个沙箱解决方案,一个Baz类库项目,一个引用BazBar类库项目和一个引用BarFoo控制台应用程序项目。

From the Foo project I'm able to access and use BazThing , a type defined in the Baz project, even though Foo doesn't have a reference on Baz . Foo项目中,我可以访问和使用BazThing (在Baz项目中定义的一种类型),即使FooBaz上没有引用。

This works with NuGet packages too: if I add Entity Framework to Baz through NuGet I'm able to use the DbContext type in the Foo project. 这也适用于NuGet包:如果我通过NuGet将实体框架添加到Baz ,则可以在Foo项目中使用DbContext类型。

This is a huge problem when the projects are used to implement layer segregation. 当项目用于实现层隔离时,这是一个巨大的问题。

Developers are now allowed to access and use implementation details of the dependencies or bypass layer segregation, both "maliciously" and by mistake (in the above mentioned example, IntelliSense will happily suggests to use BazThings when typing ba without any warning). 现在,允许开发人员“恶意”和错误地访问和使用依赖项或旁路层隔离的实现详细信息(在上述示例中,IntelliSense会在输入ba而没有任何警告的情况下愉快地建议使用BazThings )。

Is this how things will work from now on, or are we missing something? 从现在开始这是工作方式吗,还是我们缺少了什么?

Is it possible to prevent/inhibit this behavior somehow? 是否有可能以某种方式预防/抑制这种行为?

Where can I find documentation about this behavior? 在哪里可以找到有关此行为的文档?

That is intended behavior of modern NuGet/msbuild. 这是现代NuGet / msbuild的预期行为。 It is called meta-packages / transitive dependencies and used for example for the NETStandard.Library package to include all libraries of the base class library. 它被称为元包 / 传递依赖项 ,例如用于NETStandard.Library包,以包括基类库的所有库。 I do not think there is a way hiding them. 我认为没有办法隐藏它们。 Expect this feature to be added to full .NET Framework projects within the next releases of VS. 希望此功能可以在VS的下一版本中添加到完整的.NET Framework项目中。

Aside of your questions, my personal opinion here is that hiding artifacts behind reference trees is maybe useful at first sight but does not bring any architectural benefit. 除了您的问题外,我个人的观点是,将人造物隐藏在参考树后面可能乍一看很有用,但不会带来任何架构上的好处。 A loaded assembly can be invoked. 可以调用已加载的程序集。 One way or the other. 一种或另一种方式。 Layering, layer bridging and adherence to architecture can be only teached/learned/reviewed/documented. 分层,层桥接和对体系结构的依从性只能被教导/学习/审查/记录。 Teach the devs but do not build walls around them. 教开发者,但不要在他们周围筑墙。 Discipline should not be enforced by the artifacts but by the devs themselves. 纪律不应由工件强制执行,而应由开发人员自己强制执行。

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

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