Skip to content

Commit 38f221b

Browse files
Update README.md
1 parent 4971836 commit 38f221b

File tree

1 file changed

+47
-25
lines changed

1 file changed

+47
-25
lines changed

.github/README.md

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,29 @@ Reflex's default strategy for creating containers involves initially generating
210210
graph
211211
ProjectContainer --> BootScene
212212
ProjectContainer --> LobbyScene
213-
ProjectContainer --> GameModeOneScene
213+
ProjectContainer --> GameScene
214214
ProjectContainer --> GameModeTwoScene
215215
```
216216

217-
### Scene Parent Override
218-
219-
If you want a scene to inherit services from another scene, you can use the `ReflexSceneManager::OverrideSceneParentContainer` method. This feature provides developers with more granular control over which parent container is used for each newly loaded scene.
217+
### Parent Override Scope
218+
The `ParentOverrideScope` class allows you to temporarily override the default parent container for all containers created via `ContainerBuilder`. Once an instance of this scope is created, it remains active until explicitly disposed, during which time all newly built containers will inherit from the overridden parent instead of the default one.
219+
This is particularly useful for instance when you want one scene to inherit services from another scene, enabling a more granular control over which parent container is used for each newly loaded scene.
220220

221221
```csharp
222-
// Scene Manager Sample
223-
var bootScene = SceneManager.GetSceneByName("Boot");
224-
var sessionScene = SceneManager.LoadScene("Session", new LoadSceneParameters(LoadSceneMode.Additive));
225-
ReflexSceneManager.OverrideSceneParentContainer(scene: sessionScene, parent: bootScene.GetSceneContainer());
226-
227-
// Addessable Sample
228-
var handle = Addressables.LoadSceneAsync("Session", LoadSceneMode.Additive, activateOnLoad: false);
229-
await handle.Task;
230-
var bootScene = SceneManager.GetSceneByName("Boot");
231-
ReflexSceneManager.OverrideSceneParentContainer(scene: handle.Result.Scene, parent: bootScene.GetSceneContainer());
232-
handle.Result.ActivateAsync();
222+
var bootSceneContainer = gameObject.scene.GetSceneContainer();
223+
var parentOverrideScope = new ParentOverrideScope(bootSceneContainer);
224+
225+
// If you are loading scenes without addressables
226+
SceneManager.LoadSceneAsync("Lobby", LoadSceneMode.Additive).completed += operation =>
227+
{
228+
parentOverrideScope.Dispose();
229+
};
230+
231+
// If you are loading scenes with addressables
232+
Addressables.LoadSceneAsync("Lobby", LoadSceneMode.Additive).Completed += operation =>
233+
{
234+
parentOverrideScope.Dispose();
235+
};
233236
```
234237

235238
By utilizing this API, you can create hierarchical structures such as the one shown below:
@@ -238,8 +241,6 @@ By utilizing this API, you can create hierarchical structures such as the one sh
238241
graph
239242
ProjectContainer-->BootScene
240243
BootScene-->LobbyScene
241-
LobbyScene-->GameModeOneScene
242-
LobbyScene-->GameModeTwoScene
243244
```
244245

245246

@@ -286,6 +287,35 @@ using var scopedContainer = parentContainer.Scope(builder =>
286287
});
287288
```
288289

290+
### Extra Installer Scope
291+
The `ExtraInstallerScope` provides a mechanism for injecting additional bindings into containers after their initial setup. Once an instance of this scope is created, it remains active until explicitly disposed, it acts as a post-installation hook for all containers built through `ContainerBuilder`.
292+
This is especially useful in dynamic scenarios—for example, if you have fetched asynchronous dependencies in a boot scene and want to ensure they are available when transitioning into a gameplay scene. It supports use cases resembling a state machine, where the application moves from an "initializing" state to a "ready" state, injecting the required dependencies at the appropriate time.
293+
294+
Below is an example of a Boot scene that retrieves a remote configuration before transitioning to the Game scene. By the time the Game scene is loaded, the remote configuration is already registered within the Game scene's scope container.
295+
296+
```csharp
297+
public class Boot : MonoBehaviour
298+
{
299+
private async void Start()
300+
{
301+
var remoteConfig = await FetchRemoteConfigAsync();
302+
303+
var extraInstallerScope = new ExtraInstallerScope(gameSceneScopeContainerBuilder =>
304+
{
305+
gameSceneScopeContainerBuilder.AddSingleton(remoteConfig);
306+
});
307+
308+
SceneManager.LoadSceneAsync("Game").completed += operation => extraInstallerScope.Dispose();
309+
}
310+
311+
private async Task<string> FetchRemoteConfigAsync()
312+
{
313+
await Task.Delay(1000); // Simulate network delay
314+
return "remote config data";
315+
}
316+
}
317+
```
318+
289319
## 🔩 Bindings
290320

291321
### AddSingleton (From Type)
@@ -551,14 +581,6 @@ An alternative approach is to utilize the `GameObjectSelfInjector`, which can be
551581

552582
## 🧩 Extensions
553583

554-
### ParentOverrideScope
555-
The `ParentOverrideScope` allows you to temporarily override the default parent container for all containers created via `ContainerBuilder`. Once an instance of this scope is created, it remains active until explicitly disposed, during which time all newly built containers will inherit from the overridden parent instead of the default one.
556-
This is particularly useful when you want one scene to inherit services from another, enabling fine-grained control over which parent container is used for each newly loaded scene.
557-
558-
### ExtraInstallerScope
559-
The `ExtraInstallerScope` provides a mechanism for injecting additional bindings into containers after their initial setup. Once an instance of this scope is created, it remains active until explicitly disposed, it acts as a post-installation hook for all containers built through `ContainerBuilder`.
560-
This is especially useful in dynamic scenarios—for example, if you have fetched asynchronous dependencies in a boot scene and want to ensure they are available when transitioning into a gameplay scene. It supports use cases resembling a state machine, where the application moves from an "initializing" state to a "ready" state, injecting the required dependencies at the appropriate time.
561-
562584
### GetSceneContainer
563585
```csharp
564586
// Allows you to get a scene container, allowing you to resolve/inject dependencies in a different way during runtime

0 commit comments

Comments
 (0)