Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Dec 18, 2020
1 parent ac97f96 commit ad03fda
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 8 deletions.
208 changes: 206 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Releases](https://img.shields.io/github/release/hadashiA/VContainer.svg)](https://github.com/hadashiA/VContainer/releases)
[![openupm](https://img.shields.io/npm/v/jp.hadashikick.vcontainer?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/jp.hadashikick.vcontainer/)

**VContainer** is an fatest DI (Dependency Injection) library running on Unity (Game Engine).
The extra fast DI (Dependency Injection) library running on Unity Game Engine.

"V" means making Unity's initial "U" more thinner and solid ... !

Expand All @@ -24,13 +24,217 @@
- Pre IL Code generation optimization mode
- ECS Integration *beta*

## Performance

![](./website/static/img/benchmark_result.png)

## Installation

*Requires Unity 2018.4+*

### Install via UPM (using Git URL)

1. Navigate to your project's Packages folder and open the manifest.json file.
2. Add this line below the "dependencies": { line
- ```json title="Packages/manifest.json"
"jp.hadashikick.vcontainer": "https://github.com/hadashiA/VContainer.git?path=VContainer/Assets/VContainer#1.4.0",
```
3. UPM should now install the package.

### Install via OpenUPM


1. The package is available on the [openupm registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli).
2. Execute the openum command.
- ```
openupm add jp.hadashikick.vcontainer
```

### Install manually (using .unitypackage)

1. Navigate to your project's Packages folder and open the manifest.json file.
2. Add this line below the "dependencies": { line
- ```json title="Packages/manifest.json"
"nuget.mono-cecil": "0.1.6-preview",
```
3. Download the .unitypackage from [releases](https://github.com/hadashiA/VContainer/releases) page.
4. Open VContainer.x.x.x.unitypackage

## Basic Usage

## Basic Usage

First, create a scope. References are automatically resolved for types registered here.

```csharp
public class GameLifetimeScope : LifetimeScope
{
public override void Configure(IContainerBuilder builder)
{
builder.RegisterEntryPoint<ActorPresenter>(Lifetime.Scoped);

builder.Register<CharacterService>(Lifetime.Scoped);
builder.Register<IRouteSearch, AStarRouteSearch>(Lifetime.Singleton);

builder.RegisterComponentInHierarchy<ActorsView>();
}
}
```

Where definitions of classes are

```csharp
public interface IRouteSearch
{
}

public class RouteSearch : IRouteSearch
{
}

public class CharacterService
{
readonly IRouteSearch routeSearch;

public CharacterService(IRouteSearch routeSearch)
{
this.routeSearch = routeSearch;
}
}
```

```csharp
public class ActorsView : MonoBehaviour
{
}
```

and

```csharp
public class ActorPresenter : IStartable
{
readonly CharacterService service;
readonly ActorsView actorsView;

public ActorPresenter(
CharacterService service,
ActorsView actorsView)
{
this.service = service;
this.actorsView = actorsView;
}

void IStartable.Start()
{
// Scheduled at Start () on VContainer's own PlayerLoopSystem.
}
}
```

- Now, the pet of PetOwner is automatically set as the instance of Cat when Person is resolved to the instance of PetOwner
- VContainer can have a Pure C # class as an entry point. (Many callbacks like Start, Update, etc..) This facilitates "separation of domain logic and presentation"

### Flexible Scoping with async

LifetimeScope can dynamically create children. This allows you to deal with the asynchronous resource loading that often occurs in games.

```csharp
public void LoadLevel()
{
// ... Loading some assets
// Create a child scope
instantScope = currentScope.CreateChild();

// Create a child scope with LifetimeScope prefab
instantScope = currentScope.CreateChildFromPrefab(lifetimeScopePrefab);

// Create a child with additional registration
instantScope = currentScope.CreateChildFromPrefab(
lifetimeScopePrefab,
builder =>
{
// Extra Registrations ...
});

instantScope = currentScope.CreateChild(builder =>
{
// ExtraRegistrations ...
});

instantScope = currentScope.CreateChild(extraInstaller);
}

public void UnloadLevel()
{
instantScope.Dispose();
}
```

In addition, you can create a parent-child relationship with LifetimeScope in an Additive scene.

```csharp
class SceneLoader
{
readonly LifetimeScope currentScope;

public SceneLoader(LifetimeScope currentScope)
{
currentScope = currentScope; // Inject the LifetimeScope to which this class belongs
}

IEnumerator LoadSceneAsync()
{
// LifetimeScope generated in this block will be parented by `this.lifetimeScope`
using (LifetimeScope.EnqueueParent(currentScope))
{
// If this scene has a LifetimeScope, its parent will be `parent`.
var loading = SceneManager.LoadSceneAsync("...", LoadSceneMode.Additive);
while (!loading.isDone)
{
yield return null;
}
}
}

// UniTask example
async UniTask LoadSceneAsync()
{
using (LifetimeScope.EnqueueParent(parent))
{
await SceneManager.LoadSceneAsync("...", LoadSceneMode.Additive);
}
}
}
```

```csharp
// LifetimeScopes generated during this block will be additionally Registered.
using (LifetimeScope.Enqueue(builder =>
{
// Register for the next scene not yet loaded
builder.RegisterInstance(extraInstance);
}))
{
// Loading the scene..
}
```

## Documentation

Visit [vcontainer.hadashikick.jp](https://vcontainer.hadashikick.jp) to view the full documentation.

## Getting Started

Visit [vcontainer.hadashikick.jp/getting-started](https://vcontainer.hadashikick.jp/getting-started/installation) to get started with Next.js.
Visit [vcontainer.hadashikick.jp/getting-started](https://vcontainer.hadashikick.jp/getting-started/installation) to get started.

## Credits

VContainer is inspired by:

- [Zenject](https://github.com/modesttree/Zenject) and [Extenject]https://github.com/svermeulen/Extenject).
- [Autofac](http://autofac.org) - [Autofac Project](https://github.com/autofac/Autofac).

## License

Expand Down
3 changes: 3 additions & 0 deletions VContainer/Assets/VContainer/Editor/DebuggerWindow.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$HEADER$namespace $NAMESPACE$
{
public class $CLASS$ {$END$}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VContainer.Editor
{
public class VContainerDebuggerWindow
{

}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added docs/benchmark_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/lifecycle_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_baselifetimescope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_childlifetimescope.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_childlifetimescope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_create_lifetimescope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_gamelifetimescope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_preloadassets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_profiler_vcontainer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_profiler_zenject.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_validate_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_vcontainersettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot_vcontainersettings_collapse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

1 comment on commit ad03fda

@vercel
Copy link

@vercel vercel bot commented on ad03fda Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.