简体   繁体   English

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

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

I'm reading the documentation on Assemblies in the C# documentation, and the term activation scoping is used without much context.我正在阅读 C# 文档中有关程序集的文档,并且在没有太多上下文的情况下使用术语激活范围。 I understand the concept of scope by itself.我自己理解范围的概念。 Here is the context I found the term in:这是我在以下内容中找到该术语的上下文:

Assemblies form the fundamental units of deployment, version control, reuse, activation scoping , and security permissions for .NET-based applications.程序集构成了基于 .NET 的应用程序的部署、版本控制、重用、激活范围和安全权限的基本单元。 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.程序集采用可执行 (.exe) 或动态链接库 (.dll) 文件的形式,是 .NET 应用程序的构建块。 They provide the common language runtime with the information it needs to be aware of type implementations.它们为公共语言运行时提供了解类型实现所需的信息。

Assemblies in .NET .NET 中的程序集

Yes, this is vague.是的,这是模糊的。

"Activation" does not have a precise technical meaning in the CLR, or in C#. “激活”在 CLR 或 C# 中没有精确的技术含义。 But it is a technical term in COM, the Component Object Model, which is the native Windows component model that predates and co-exists with .NET.但它是 COM 中的一个技术术语,即组件对象模型,它是早于 .NET 并与 .NET 共存的原生 Windows 组件模型。

In COM Activation means "The process of loading an object in memory, which puts it into the running state."在 COM 中,激活的意思是“在内存中加载一个对象,使其进入运行状态的过程”。 (https://docs.microsoft.com/en-us/windows/win32/com/com-glossary ) (https://docs.microsoft.com/en-us/windows/win32/com/com-glossary )

You can see a holdover from this terminology in the naming of the System.Activator type, which has similar functionality to the COM activator function CoCreateInstance .您可以在System.Activator类型的命名中看到此术语的保留,它具有与 COM 激活器函数CoCreateInstance相似的功能。

In .NET a Type lives in a specific Assembly, and a Type name is unique within an Assembly.在 .NET 中,类型存在于特定的程序集中,并且类型名称在程序集中是唯一的。 At runtime Types with the same name might be contained in other Assemblies that are currently loaded into your AppDomain.在运行时,同名类型可能包含在当前加载到 AppDomain 中的其他程序集中。 But whenever you are creating an object instance (ie an "activation"), you either specify the Type (which implies a specific Assembly), or the Assembly and Type name.但是,无论何时创建对象实例(即“激活”),您要么指定类型(暗示特定程序集),要么指定程序集和类型名称。

In the normal case of writing a type name in code, the compiler will identify which referenced Assembly to use for the target Type, and if multiple Types with the same name are found at compile time, the compiler will either give you a warning CS0436 , or an error CS0433 .正常情况下,在代码中写入类型名,编译器会识别目标Type使用哪个引用的Assembly,如果在编译时发现多个同名的Type,编译器要么给你一个警告CS0436 ,或错误CS0433

In the case of Reflection, you can load a Type by name, but you always have to specify an Assembly to load the type from.在反射的情况下,您可以按名称加载类型,但您始终必须指定一个程序集来加载类型。 Notice that there's not an overload of Activator.CreateInstance that just takes a Type name, and Type.GetType also requires you to specify an Assembly.请注意,Activator.CreateInstance 并没有只采用类型名称的重载,并且Type.GetType还要求您指定一个程序集。

In either case you are "activating" the object from a specific Assembly.在任何一种情况下,您都是从特定程序集中“激活”对象。 So the Assembly defines the "scope" for the Type "activation".因此,程序集定义了类型“激活”的“范围”。

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

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