diff --git a/website/docs/integrations/entrypoint.mdx b/website/docs/integrations/entrypoint.mdx index 93d036e6..5516d818 100644 --- a/website/docs/integrations/entrypoint.mdx +++ b/website/docs/integrations/entrypoint.mdx @@ -35,6 +35,7 @@ Since it uses PlayerLoopSystem, it works even if you register at any time (e.g: | `IInitializable.Initialize()` | Immediately after building the container | | `IPostInitializable.PostInitialize()` | Late `IInitializable.Initialize()` | | `IStartable.Start()` | Nearly `MonoBehaviour.Start()` | +| `IAsyncStartable.StartAsync()` | Nearly `MonoBehaviour.Start()` | | `IPostStartable.PostStart()` | After `MonoBehaviour.Start()` | | `IFixedTickable.FixedTick()` | Nearly `MonoBehaviour.FixedUpdate()` | | `IPostFixedTickable.PostFixedTick()` | After `MonoBehaviour.FixedUpdate()` | @@ -78,7 +79,3 @@ builder.RegisterEntryPointExceptionHandler(ex => :::caution Default error logging will be skipped if you are using the RegisterEntryPointExceptionHandler. ::: - -## UniTask - -If you are using UniTask, you can use `IAsyncStartable`. see also [UniTask Integration](../integrations/unitask) diff --git a/website/docs/integrations/unitask.mdx b/website/docs/integrations/unitask.mdx index 2146ad3d..35dcd7ac 100644 --- a/website/docs/integrations/unitask.mdx +++ b/website/docs/integrations/unitask.mdx @@ -5,11 +5,12 @@ sidebar_label: UniTask [UniTask](https://github.com/Cysharp/UniTask) is a library that brings fast and powerful [`async`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/async)/[`await`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/await) support to Unity. Its API is nearly identical to that of .NET's standard [Task-based asynchronous pattern](https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/task-based-asynchronous-pattern-tap), but optimized for Unity's player loop. It also adds `async`/`await` support for Unity's built-in asynchronous operations such as [`UnityWebRequest`](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest). -If you have the `com.cysharp.unitask` package installed in your project, the following features will automatically be enabled. +If you have the `com.cysharp.unitask` package installed in your project, +The `VCONTAINER_UNITASK_INTEGRATION` compiler symbol is automatically enabled and the following features will automatically be enabled. ## `IAsyncStartable` -Entry points can use the `IAsyncStartable` phase, which returns a `UniTask`. +If `VCONTAINER_UNITASK_INTEGRATION` is enabled, `IAsyncStartable` uses UniTask as return value. ```csharp public class FooController : IAsyncStartable @@ -40,7 +41,6 @@ If you want to schedule the process at different times, you can use UniTask's `P ```csharp await UniTask.Yield(PlayerLoopTiming.FixedUpdate); ``` - Note that all `StartAsync` calls will be scheduled for simultaneous execution on the main thread (unless otherwise specified within each implementation), and future `PlayerLoop` phases will *not* wait for them to complete. See [UniTask's `PlayerLoop` documentation](https://github.com/Cysharp/UniTask#playerloop) for more information. diff --git a/website/docs/optimization/source-generator.mdx b/website/docs/optimization/source-generator.mdx index 9c4c0663..1d3c5c3e 100644 --- a/website/docs/optimization/source-generator.mdx +++ b/website/docs/optimization/source-generator.mdx @@ -46,10 +46,17 @@ See more information: ## Which classes are target to code generation? -By default, classes in the assembly that reference VContainer.asmdef are target to code generation. +Classes that meet the following conditions are eligible for 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. +- 1. Classes in assemblies that reference VContainer.asmdef. +- 2. And classes with `[InjectIgnoere]` attribute are excluded. +- 3. And one of the following is satisfied. + - `[Inject]` attribute is attached to. + - the type specified as a parameter of the any `Register*` method. +If you want to explicitly add it to the target, you can control it by granting the `[Inject]` attribute, if you want to explicitly exclude it from the target, you can control it by granting the `[InjectIgnore]` attribute. + +Note that classes that are targeted for code generation are `[Preserve]` and therefore not subject to code-stripping by IL2CPP. ### Limitation diff --git a/website/docs/registering/register-callbacks.mdx b/website/docs/registering/register-callbacks.mdx index 8bbb9f6d..ecf9f308 100644 --- a/website/docs/registering/register-callbacks.mdx +++ b/website/docs/registering/register-callbacks.mdx @@ -17,3 +17,13 @@ builder.RegisterBuildCallback(container => - We can use `IObjectResolver` as a callback argument. - For more information about `IObjectResolver`, see [Container API](../resolving/container-api) + +## Container Dispose Callback + +```cs +builder.RegisterDisposeCallback(container => +{ + // Processes you want to perform in which the container is disposed. +}); +``` + diff --git a/website/docs/registering/register-type.mdx b/website/docs/registering/register-type.mdx index 21ba9a03..6fbe12f4 100644 --- a/website/docs/registering/register-type.mdx +++ b/website/docs/registering/register-type.mdx @@ -191,7 +191,7 @@ If you want the container to manage the created instances, consider using the fo - [RegisterComponent(...)](./register-monobehaviour) ::: -## Register instance as interface +## Register instance as interface Use `As*` declarations. @@ -223,7 +223,6 @@ builder.Register(Lifetime.Singleton) It can resolve like this: - ```csharp class SomeService { @@ -240,3 +239,28 @@ class OtherClass public OtherClass(string hogehoge) { /* ... */ } } ``` + +## Register Open Generics + +```csharp +class GenericType +{ + // ... +} +``` + +```csharp +builder.Register(typeof(GenericType<>), Lifetime.Singleton); +``` + +It can resolve like this: + +```csharp +class SomeService +{ + public SomeService(GenericType closedGenericType) { /* ... */ } +} +``` + +In this case, the concrete type is constructed at runtime. +We have confirmed that this works with IL2CPP from Unity 2022.1 onwards, but older versions may not support dynamic typedefs. diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/entrypoint.mdx b/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/entrypoint.mdx index 0aa2e8d7..5516d818 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/entrypoint.mdx +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/entrypoint.mdx @@ -6,7 +6,7 @@ VContainer allows plain C# to be the starting point for application processing. Using it instead of MonoBehaviour, which has a lot of features, can help you build a simple control flow. ```csharp -clas FooController : IStartable +class FooController : IStartable { void IStartable.Start() { @@ -30,11 +30,12 @@ Since it uses PlayerLoopSystem, it works even if you register at any time (e.g: ## Available interfaces -| VContaienr entry point | Timing | +| VContainer entry point | Timing | |:--------------------------------------|:----------------------------------| | `IInitializable.Initialize()` | Immediately after building the container | | `IPostInitializable.PostInitialize()` | Late `IInitializable.Initialize()` | | `IStartable.Start()` | Nearly `MonoBehaviour.Start()` | +| `IAsyncStartable.StartAsync()` | Nearly `MonoBehaviour.Start()` | | `IPostStartable.PostStart()` | After `MonoBehaviour.Start()` | | `IFixedTickable.FixedTick()` | Nearly `MonoBehaviour.FixedUpdate()` | | `IPostFixedTickable.PostFixedTick()` | After `MonoBehaviour.FixedUpdate()` | @@ -53,6 +54,14 @@ And [Unity - Manual: Order of Execution for Event Functions](https://docs.unity3d.com/Manual/ExecutionOrder.html) ::: +### async + +`IAsyncStartable` is available as a variant of IStartable. +It has the same timing as IStartable, but `async Awaitable StartAsync()` is available. + +If you are a UniTask user, you can also choose the UniTask version of StartAsync. +[UniTask integration](../integrations/unitask) + ## Handle of the exception that was not caught On the application side, exceptions thrown in processes such as Start() and Tick() cannot be caught outside. @@ -70,7 +79,3 @@ builder.RegisterEntryPointExceptionHandler(ex => :::caution Default error logging will be skipped if you are using the RegisterEntryPointExceptionHandler. ::: - -## UniTask - -If you are using UniTask, you can use `IAsyncStartable`. see also [UniTask Integration](../integrations/unitask) \ No newline at end of file diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/unitask.mdx b/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/unitask.mdx index 2146ad3d..35dcd7ac 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/unitask.mdx +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/integrations/unitask.mdx @@ -5,11 +5,12 @@ sidebar_label: UniTask [UniTask](https://github.com/Cysharp/UniTask) is a library that brings fast and powerful [`async`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/async)/[`await`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/await) support to Unity. Its API is nearly identical to that of .NET's standard [Task-based asynchronous pattern](https://docs.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/task-based-asynchronous-pattern-tap), but optimized for Unity's player loop. It also adds `async`/`await` support for Unity's built-in asynchronous operations such as [`UnityWebRequest`](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest). -If you have the `com.cysharp.unitask` package installed in your project, the following features will automatically be enabled. +If you have the `com.cysharp.unitask` package installed in your project, +The `VCONTAINER_UNITASK_INTEGRATION` compiler symbol is automatically enabled and the following features will automatically be enabled. ## `IAsyncStartable` -Entry points can use the `IAsyncStartable` phase, which returns a `UniTask`. +If `VCONTAINER_UNITASK_INTEGRATION` is enabled, `IAsyncStartable` uses UniTask as return value. ```csharp public class FooController : IAsyncStartable @@ -40,7 +41,6 @@ If you want to schedule the process at different times, you can use UniTask's `P ```csharp await UniTask.Yield(PlayerLoopTiming.FixedUpdate); ``` - Note that all `StartAsync` calls will be scheduled for simultaneous execution on the main thread (unless otherwise specified within each implementation), and future `PlayerLoop` phases will *not* wait for them to complete. See [UniTask's `PlayerLoop` documentation](https://github.com/Cysharp/UniTask#playerloop) for more information. diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/optimization/source-generator.mdx b/website/i18n/ja/docusaurus-plugin-content-docs/current/optimization/source-generator.mdx index 86a22027..592248c1 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/optimization/source-generator.mdx +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/optimization/source-generator.mdx @@ -45,10 +45,17 @@ RoslynAnalyzer というasset labelを付与することで、Unityはこのdll ## コード生成対象になるクラス -デフォルトでは、VContainer.asmdef の参照があるアセンブリ内のクラスはコード生成の対象になります。 +以下の条件を満たすクラスは、コード生成の対象になります。 -無駄なコード生成を抑制したい等の理由で、対象から除外したい場合は、型に対して `[InjectIgnore]` アトリビュートを付与してください。 +- 1. VContainer.asmdef を参照しているアセンブリ内のクラス。 +- 2. かつ、`[InjectIgnoere]` attributeがついたクラスは除く。 +- 3. かつ、以下のいずれかを満たす。 + - `[Inject]` attributeが付与されている + - `IContainerBuilder.Register*` メソッドのパラメータとして指定されている型 +もし、明示的に対象に加えたい場合は`[Inject]` attribute を、明示的に対象外にしたい場合は`[InjectIgnore]` attributeを付与することでコントロールできます。 + +尚、コード生成の対象になったクラスは、`[Preserve]` されるため、IL2CPPによるコードstrippingの対象になりません。 ## 制限事項 diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-callbacks.mdx b/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-callbacks.mdx index ab94ab93..e9aaa66c 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-callbacks.mdx +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-callbacks.mdx @@ -16,4 +16,15 @@ builder.RegisterBuildCallback(container => ``` - We can use `IObjectResolver` as a callback argument. -- For more information about `IObjectResolver`, see [Contaienr API](../resolving/container-api) \ No newline at end of file +- For more information about `IObjectResolver`, see [Contaienr API](../resolving/container-api) + + +## Container Dispose Callback + +```cs +builder.RegisterDisposeCallback(container => +{ + // Processes you want to perform in which the container is disposed. +}); +``` + diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-type.mdx b/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-type.mdx index 74a3cdd0..7adc3b88 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-type.mdx +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/registering/register-type.mdx @@ -240,3 +240,28 @@ class OtherClass public OtherClass(string hogehoge) { /* ... */ } } ``` + +## Register Open Generics + +```csharp +class GenericType +{ + // ... +} +``` + +```csharp +builder.Register(typeof(GenericType<>), Lifetime.Singleton); +``` + +It can resolve like this: + +```csharp +class SomeService +{ + public SomeService(GenericType closedGenericType) { /* ... */ } +} +``` + +In this case, the concrete type is constructed at runtime. +We have confirmed that this works with IL2CPP from Unity 2022.1 onwards, but older versions may not support dynamic typedefs. \ No newline at end of file