.NET 5 的重大改变:消失的历史技术

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在本文中,我们将回顾一些未能进入.NET Core的历史性.NET技术。有趣之处在于,这些技术的API被复制过来了,这暗示着微软当时在考虑将来在.NET Core中对它们进行实现。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"全局程序集缓存"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"全局程序集缓存(GAC)背后的理论是,所有.NET库都可以存储在单个集中的位置。在这种方式下,它与"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/Component_Object_Model","title":"","type":null},"content":[{"type":"text","text":"COM"}]},{"type":"text","text":"库类似。但与COM不同的是,它可以存储每个库的多个版本。通过这种方式,微软希望可以避免困扰90年代应用程序的“DLL地狱”情景。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是,版本问题仍然存在。此外,获得代码签名证书的需要以及Windows Vista带来的安全性的增加使得GAC成为一项令人讨厌的技术。到.NET 4.5发布时,几乎没有应用程序将GAC用于非微软库。主要的例外是商业库,但即使是这些库也已经转向了对NuGet更友好的交付模型。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此,也就不奇怪,微软在.NET Core中从根本上改变了他们的哲学。在新模型中,所有库依赖项都与应用程序一起部署,从而使得应用程序可以与其他.NET Core应用程序隔离开来。因此,.NET Core中没有GAC的概念。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"尽管如此,GAC API在.NET Core中仍然存在。它们所做的事情不多,例如,指示程序集是否在GAC中的属性被硬编码为返回false。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为了进一步明确意图,所有的GAC API现在都被标记为已过时,微软正考虑在未来的版本中删除它们。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Remoting"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/.NET_Remoting","title":"","type":null},"content":[{"type":"text","text":".NET Remoting"}]},{"type":"text","text":"是受"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/Distributed_Component_Object_Model","title":"","type":null},"content":[{"type":"text","text":"DCOM"}]},{"type":"text","text":"和"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/Java_remote_method_invocation","title":"","type":null},"content":[{"type":"text","text":"Java Remoting(Java RMI)"}]},{"type":"text","text":"的启发。这三种方法的基本思想都是一个应用程序可以使用代理对象来操作在另一个应用程序中运行的真实对象。虽然它在技术上可以工作,但.NET Remoting从来就没有流行过,因为要正确地使用它很难,而且人们一般认为它很脆弱。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"考虑到这一点,.NET Core从未实现过.NET Remoting API。就像GAC API一样,它只有不可操作的占位符。因此,它们也被标记为已过时,而最终目的是将其删除。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"代码访问安全"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"继续这个主题,"},{"type":"link","attrs":{"href":"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/misc\/code-access-security","title":"","type":null},"content":[{"type":"text","text":"代码访问安全(CAS)"}]},{"type":"text","text":"是另一种API被复制到.NET Core中,但被标记为已过时的.NET Framework技术。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"代码访问安全创建于Docker等隔离容器之前。在.NET Framework时代,多个应用程序会托管在单个Internet Information Server(IIS)实例中。理论上,每个应用程序都将被隔离到一个单独的应用程序域中,但要打破这种隔离并干扰在IIS中运行的其他应用程序并不难。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"代码访问安全的创建就是为了限制这种可能的损害。其基本思想是,危险的API会被加上表示风险的属性。IIS之类的主机可以配置为运行具有不同“信任”级别的应用程序,从理论上讲,是将它们放入一个沙箱中。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"CAS的另一个用途是用于浏览器托管的应用程序。早在Silverlight出现之前,就已经可以在Internet Explorer中运行Windows窗体应用程序了。应用程序的信任级别部分取决于它是从哪里加载的,内部站点会获得更高的权限。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是和许多早期的.NET技术一样,要正确地实现CAS很困难。恶意应用程序有许多方法可以绕过CAS限制,而良性应用程序却常常为这些限制所限。结果,浏览器托管的应用程序很快就把它禁用了,而IIS在很大程度上忽略了CAS信任级别。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"Thread.Abort"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这可能会令你感到惊讶。"},{"type":"link","attrs":{"href":"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.threading.thread.abort","title":"","type":null},"content":[{"type":"text","text":"Thread.Abort"}]},{"type":"text","text":"在.NET Core中从未实现过。虽然它总是被认为有危险,但总也不可避免。在ASP.NET中,像请求超时或客户端断开连接这样简单的事情就会触发一个"},{"type":"codeinline","content":[{"type":"text","text":"Thread.Abort"}]},{"type":"text","text":"调用。如果你没有认真地编写代码进行处理,这可能会导致资源泄漏,比如获取的锁或打开的数据库事务。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"到ASP.NET Core被创建时,"},{"type":"codeinline","content":[{"type":"text","text":"CancellationToken"}]},{"type":"text","text":"已成为一个安全且被广泛接受的"},{"type":"codeinline","content":[{"type":"text","text":"Thread.Abort"}]},{"type":"text","text":"替代者,因此就不需要在.NET Core的第一个版本中实现它了。尽管.NET Core已经将其功能扩展到Web站点之外,但其他主要的应用程序框架都不需要"},{"type":"codeinline","content":[{"type":"text","text":"Thread.Abort"}]},{"type":"text","text":",因此它会继续抛出"},{"type":"codeinline","content":[{"type":"text","text":"PlatformNotSupportedException"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在.NET 5中,该方法终被标记为已过时。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"原文链接:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/www.infoq.com\/news\/2020\/12\/net-5-breaking-changes-2\/","title":"","type":null},"content":[{"type":"text","text":".NET 5 Breaking Changes: Historic Technologies"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章