.NET Core 中没有 AppDomains!为什么? [英] No AppDomains in .NET Core! Why?

查看:27
本文介绍了.NET Core 中没有 AppDomains!为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

微软选择在 .NET Core 中不支持 AppDomains 是否有充分的理由?

Is there a strong reason why Microsoft chose not to support AppDomains in .NET Core?

AppDomains 在构建长时间运行的服务器应用程序时特别有用,我们可能希望在不关闭服务器的情况下以一种优雅的方式更新服务器加载的程序集.

AppDomains are particularly useful when building long running server apps, where we may want to update the assemblies loaded by the server is a graceful manner, without shutting down the server.

如果没有 AppDomains,我们将如何在长时间运行的服务器进程中替换我们的程序集?

Without AppDomains, how are we going to replace our assemblies in a long running server process?

AppDomains 还为我们提供了一种隔离服务器代码不同部分的方法.例如,自定义 websocket 服务器可以在主应用程序域中拥有套接字代码,而我们的服务在辅助应用程序域中运行.

AppDomains also provide us a way to isolate different parts of server code. Like, a custom websocket server can have socket code in primary appdomain, while our services run in secondary appdomain.

没有 AppDomains,上述场景是不可能的.

Without AppDomains, the above scenario is not possible.

我可以看到一个论点,它可能谈论使用云的虚拟机概念来处理程序集更改,而不必招致 AppDomains 的开销.但这是微软的想法或说法吗?或者他们有针对上述情况的特定原因和替代方案?

I can see an argument that may talk about using VMs concept of Cloud for handling assembly changes and not having to incur the overhead of AppDomains. But is this what Microsoft thinks or says? or they have a specific reason and alternatives for the above scenarios?

推荐答案

.NET Standard 2 和 .NET Core 2 的更新

在 .NET Standard 2 中,AppDomain 就在其中.但是,该 API 的许多部分会为 .NET Core 抛出 PlatformNotSupportedException.

Update for .NET Standard 2 and .NET Core 2

In .NET Standard 2 the AppDomain class is in there. However, many parts of that API will throw a PlatformNotSupportedException for .NET Core.

它仍然存在的主要原因是基本的东西,比如注册一个工作的未处理的异常处理程序.

The main reason it's still in there is for basic stuff like registering an unhandled exception handler which will work.

.NET Standard FAQ 有这样的解释:

AppDomain 是 .NET Standard 的一部分吗?

Is AppDomain part of .NET Standard?

AppDomain 类型是 .NET Standard 的一部分.并非所有平台都支持创建新的应用程序域,例如 .NET Core 不会,因此方法 AppDomain.CreateDomain 在 .NET Standard 中可用时可能会抛出 PlatformNotSupportedException.

The AppDomain type is part of .NET Standard. Not all platforms will support the creation of new app domains, for example, .NET Core will not, so the method AppDomain.CreateDomain while being available in .NET Standard might throw PlatformNotSupportedException.

我们在 .NET Standard 中公开这种类型的主要原因是使用率相当高,通常与创建新应用域无关,而是用于与当前应用域交互,例如注册未处理的异常处理程序或请求应用程序的基目录.

The primary reason we expose this type in .NET Standard is because the usage is fairly high and typically not associated with creating new app domains but for interacting with the current app domain, such as registering an unhandled exception handler or asking for the application's base directory.

除此之外,最佳答案 和其他答案也很好地解释了为什么 AppDomain 的大部分仍然被削减(例如抛出一个不受支持的异常).

Apart from that, the top answer and other answers also nicely explain why the bulk of AppDomain was still cut (e.g. throws a not supported exception).

这篇关于.NET Core 中没有 AppDomains!为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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