Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[website] Add docs about [InjectIgnore] #511

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions website/docs/optimization/source-generator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ Then, from the inspector, do the following:
See more information:
- https://docs.unity3d.com/Manual/roslyn-analyzers.html

## Limitation
## Which classes are target to code generation?

By default, classes in the assembly that reference VContainer.asmdef are target to code generation.

If you want to exclude a target for reasons such as wanting to suppress unnecessary code generation, please add the [InjectIgnore] attribute to the type.


### Limitation

SourceGenerator acceleration is not supported for type definitions like the following. (works by reflection)

- C# source without reference to VContainer.asmdef
- Nested classes
- Struct
- If the access level is less than internal (for example, private), even if `[Inject]` is added, SourceGenerator is not supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ RoslynAnalyzer というasset labelを付与することで、Unityはこのdll

この状態でコンパイルを走らせると、VContaienrは自動的にDIのための高速なコードを生成するようになります。

## コード生成対象になるクラス

デフォルトでは、VContainer.asmdef の参照があるアセンブリ内のクラスはコード生成の対象になります。

無駄なコード生成を抑制したい等の理由で、対象から除外したい場合は、型に対して `[InjectIgnore]` アトリビュートを付与してください。


## 制限事項

現在、以下のような型定義に対しては、SourceGeneratorの対象にはなりません。注意して下さい。
(暗黙のうちにリフレクションでの動作にフォールバックされます)

- VContainer.asmdef の参照がないC#コード
- ネストしたクラス
- struct型
- アクセスレベルが internal未満のコンストラクタやメソッドやプロパティ (たとえば `[Inject]`アトリビュートがついていても、privateなもの)
Expand Down