在 C# 程序集的上下文中,激活作用域指的是什么?

In the context of assemblies in C#, what does activation scoping refer to?

我正在阅读 C# 文档中有关程序集的文档,并且在没有太多上下文的情况下使用术语激活作用域。我自己理解范围的概念。这是我在以下位置找到该术语的上下文:

Assemblies form the fundamental units of deployment, version control, reuse, activation scoping, and security permissions for .NET-based applications. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (.dll) files, and are the building blocks of .NET applications. They provide the common language runtime with the information it needs to be aware of type implementations.

Assemblies in .NET

是的,这是模糊的。

"Activation" 在 CLR 或 C# 中没有精确的技术含义。但它是 COM 中的一个技术术语,即组件对象模型,它是原生的 Windows 组件模型,早于 .NET 并与之共存。

在 COM 激活中表示 "The process of loading an object in memory, which puts it into the running state." (https://docs.microsoft.com/en-us/windows/win32/com/com-glossary)

您可以在 System.Activator type, which has similar functionality to the COM activator function CoCreateInstance 的命名中看到该术语的保留。

在 .NET 中,类型存在于特定的程序集中,并且类型名称在程序集中是唯一的。在运行时,具有相同名称的类型可能包含在当前加载到您的 AppDomain 中的其他程序集中。但是每当您创建对象实例(即 "activation")时,您要么指定类型(这意味着特定的程序集),要么指定程序集和类型名称。

在代码中编写类型名称的正常情况下,编译器将识别将哪个引用程序集用于目标类型,如果在编译时发现多个具有相同名称的类型,编译器将给出你一个警告 CS0436, or an error CS0433.

在反射的情况下,您可以按名称加载类型,但您始终必须指定一个程序集以从中加载类型。请注意,没有仅采用类型名称的 Activator.CreateInstance 重载,并且 Type.GetType 还需要您指定一个程序集。

在任何一种情况下,您都是 "activating" 来自特定程序集的对象。因此程序集为类型 "activation" 定义了 "scope"。