Skip to content

Commit

Permalink
Merge pull request #684 from hadashiA/ku/website/v1.16.0
Browse files Browse the repository at this point in the history
[website] Update docs
  • Loading branch information
hadashiA authored Jun 23, 2024
2 parents e75c3d4 + ad220b9 commit 129dc92
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 23 deletions.
5 changes: 1 addition & 4 deletions website/docs/integrations/entrypoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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()` |
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions website/docs/integrations/unitask.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions website/docs/optimization/source-generator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions website/docs/registering/register-callbacks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
});
```

28 changes: 26 additions & 2 deletions website/docs/registering/register-type.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -223,7 +223,6 @@ builder.Register<SomeService>(Lifetime.Singleton)

It can resolve like this:


```csharp
class SomeService
{
Expand All @@ -240,3 +239,28 @@ class OtherClass
public OtherClass(string hogehoge) { /* ... */ }
}
```

## Register Open Generics

```csharp
class GenericType<T>
{
// ...
}
```

```csharp
builder.Register(typeof(GenericType<>), Lifetime.Singleton);
```

It can resolve like this:

```csharp
class SomeService
{
public SomeService(GenericType<int> 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()` |
Expand All @@ -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.
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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の対象になりません。

## 制限事項

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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.
});
```

Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,28 @@ class OtherClass
public OtherClass(string hogehoge) { /* ... */ }
}
```

## Register Open Generics

```csharp
class GenericType<T>
{
// ...
}
```

```csharp
builder.Register(typeof(GenericType<>), Lifetime.Singleton);
```

It can resolve like this:

```csharp
class SomeService
{
public SomeService(GenericType<int> 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.

0 comments on commit 129dc92

Please sign in to comment.