-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Crowdin translations by GitHub Action
- Loading branch information
1 parent
f73dff3
commit 1996090
Showing
36 changed files
with
2,190 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/i18n/en-US/docusaurus-plugin-content-docs/current/compile/001-Domain.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: 1.域的概念与使用 | ||
--- | ||
|
||
## 开始 | ||
|
||
引用包 `DotNetCore.Natasha.Domain` 或 `DotNetCore.Natasha.CSharp.Compiler.Domain`; | ||
|
||
`DotNetCore.Natasha.Domain` 为 域 的实现包。 | ||
`DotNetCore.Natasha.CSharp.Compiler.Domain` 为 Natasha 编译单元与 域的粘合包。 | ||
|
||
## 创建域 | ||
|
||
```cs | ||
//如果你想将主域转化为 NatashaDomain,请使用不带参数的初始化方法,并创建后将实例保存起来,不要重复创建。 | ||
var domain = new NatashaDomain(); | ||
//如果你想创建非主域 | ||
var domain = new NatashaDomain(key); | ||
``` | ||
|
||
## 加载插件 | ||
|
||
#### 在这之前我不得不说,一个插件如何输出完整依赖,如何屏蔽引用接口,请参照[微软文档](https://learn.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support#simple-plugin-with-no-dependencies) | ||
|
||
### 插件加载 | ||
|
||
`LoadPlugin` 方法允许用户传入插件文件路径,返回程序集。 | ||
|
||
### 程序集比较器 | ||
|
||
Natasha.Domain 自实现了程序集比较逻辑,通过 SetAssemblyLoadBehavior(AssemblyCompareInfomation loadBehavior) 方法来指定程序集依赖加载行为,例如 "AssemblyCompareInfomation.UseHighVersion" 枚举传入,将导致插件加载过程中,插件所依赖的程序集与共享域已存在的程序集进行比较,如果程序集名相同,则加载版本较高的程序集。 | ||
|
||
### 封装 API | ||
|
||
Natasha.Domain 合并了插件加载方法和程序集比较器产生了 4 个 API 方法,`LoadPluginWithHighDependency` / `LoadPluginWithLowDependency` / `LoadPluginUseDefaultDependency` / `LoadPluginWithAllDependency`. | ||
就拿第一个 API 来说,如果比对过程中找到的依赖版本有高有低,则选择高版本的依赖,而非加载低版本依赖,在使用过程中记得看注释,有问题要去 Github 提问。 | ||
|
||
### 注意事项 | ||
|
||
ALC 不允许加载引用程序集,因为引用程序集不可执行。 |
158 changes: 158 additions & 0 deletions
158
...i18n/en-US/docusaurus-plugin-content-docs/current/compile/002-SmartMode-Full.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
--- | ||
title: 2.1 智能编译模式 - 实现程序集 | ||
--- | ||
|
||
## 为何使用实现程序集 | ||
|
||
实现程序集包括逻辑的具体实现和私有字段,预热内存涨幅较少,但实现程序集具有敏感的依赖关系,需要小心使用。 | ||
|
||
## 前提条件 | ||
|
||
1. 引入 `DotNetCore.Natasha.CSharp.Compiler.Domain` Core 版本的编译域包。 | ||
2. 使用预热方法为智能编译做准备。 | ||
3. 智能编译。 | ||
|
||
## 预热案例 | ||
|
||
### 普通预热 | ||
|
||
1. 泛型预热方法将自动创建 编译域创建者 单例。 | ||
2. 传入 true 参数以达到禁用运行时程序集的作用,Natasha 将会选择内存程序集预热。 | ||
3. 第一个参数指是否从内存程序集中提取 Using Code, 设置为 true 将从实现程序集中提取 Using。 | ||
4. 第二个参数指是否从内存程序集中提取 元数据,设置为 true 将从实现程序集中提取 元数据。 | ||
|
||
```cs | ||
//注册编译域并预热方法 | ||
NatashaManagement.Preheating<NatashaDomainCreator>(true, true); | ||
``` | ||
|
||
### Using缓存预热 | ||
|
||
第一次生成将 Using Code 写入缓存文件 Natasha.Namespace.cache 中,后续重启会自动从文件中加载。 | ||
|
||
```cs | ||
//注册编译域并预热方法 | ||
NatashaManagement.Preheating<NatashaDomainCreator>(true, true,true); | ||
``` | ||
|
||
### 分开预热 | ||
|
||
```cs | ||
//注册编译域 | ||
NatashaManagement.RegistDomainCreator<NatashaDomainCreator>(); | ||
//预热方法 | ||
NatashaManagement.Preheating(true, true); | ||
``` | ||
|
||
### 过滤预热 | ||
|
||
```cs | ||
//如果存在 Dapper 主版本高于 12 的程序集,则不要将它加入缓存。 | ||
//传入排除方法 | ||
NatashaManagement.Preheating<NatashaDomainCreator>((asmName, name) => { | ||
if (asmName.Name != null) | ||
{ | ||
if (asmName.Name.Contains("Dapper") && asmName.Version!.Major > 12) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
},true, true,true); | ||
``` | ||
|
||
> 也许您的环境过于复杂,从而遇到一些意外,请您精简代码之后,确保异常能够重现,提交 issue 给 Natasha。 | ||
## 智能编译 | ||
|
||
在预热后请参考以下代码 | ||
|
||
```cs | ||
AssemblyCSharpBuilder builder = new(); | ||
var myAssembly = builder | ||
.UseRandomDomain() | ||
.UseSmartMode() //启用智能模式 | ||
.Add("public class A{ }") | ||
.GetAssembly(); | ||
``` | ||
|
||
智能模式将合并 共享域与当前域的 元数据以及 Using, 并启用语义检查. | ||
智能模式的 API 逻辑为: | ||
|
||
```cs | ||
.WithCombineReferences(item => item.UseAllReferences()) | ||
.WithCombineUsingCode(UsingLoadBehavior.WithAll) | ||
.WithReleaseCompile() | ||
.WithSemanticCheck(); | ||
``` | ||
|
||
可以参考[元数据管理与微调] 对 元数据 的合并行为进行微调。 | ||
可以参考[微调Using覆盖] 对 UsingCode 的合并行为进行微调。 | ||
|
||
## 其他案例 | ||
|
||
#### 批量排除程序集 | ||
|
||
```cs | ||
NatashaInitializer.Preheating((asmName, name) => { | ||
if (name != null) | ||
{ | ||
if (name.Contains("System")) | ||
{ | ||
if ( | ||
name.Contains("Net") || | ||
name.Contains("Xml") || | ||
name.Contains("IO") || | ||
name.Contains("Reflection") || | ||
name.Contains("Threading") || | ||
name.Contains("Security") || | ||
name.Contains("Diagnostics") || | ||
name.Contains("Data") || | ||
name.Contains("Resources.") || | ||
name.Contains("Drawing") || | ||
name.Contains("Text") || | ||
name.Contains("Globalization") || | ||
name.Contains("Service") || | ||
name.Contains("Web") || | ||
name.Contains("Window") || | ||
name.Contains("ComponentModel") | ||
) | ||
{ | ||
//排除 | ||
return true; | ||
} | ||
return false; | ||
} | ||
if (name.Contains("Natasha")) | ||
{ | ||
//加载 | ||
return false; | ||
} | ||
if (name.Contains("ConsoleApp3")) | ||
{ | ||
//加载 | ||
return false; | ||
} | ||
} | ||
return true; | ||
},true, true); | ||
``` | ||
|
||
#### 根据版本排除程序集 | ||
|
||
该示例使用 AssemblyName 进行判断程序集名称及版本, 以下代码排除了 dapper 主版本号为 12 的程序集引用文件; | ||
|
||
```cs | ||
NatashaInitializer.Preheating((asmName, name) => { | ||
if (asmName.Name != null) | ||
{ | ||
if (asmName.Name.Contains("Dapper") && asmName.Version!.Major > 12) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
``` | ||
|
||
> 减少程序集引用文件的加载,可以有效的控制内存涨幅. |
Oops, something went wrong.