All Projects → hadashiA → Vcontainer

hadashiA / Vcontainer

Licence: mit
The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.

Projects that are alternatives of or similar to Vcontainer

Qframework
Unity3D System Design Architecture
Stars: ✭ 2,326 (+655.19%)
Mutual labels:  unity, unity3d, dependency-injection
Factory
Factory for object creation and dependency injection. Works with normal C# apps or under Unity3d
Stars: ✭ 50 (-83.77%)
Mutual labels:  unity, unity3d, dependency-injection
Ditranquillity
Dependency injection for iOS (Swift)
Stars: ✭ 317 (+2.92%)
Mutual labels:  dependency-injection, di
Zcode Assetbundlepacker
Unity的AssetBundle模块扩展插件,主要目的用于简化AssetBundle打包,提供AssetBundle管理,支持热更新、支持资源包下载、支持版本控制。
Stars: ✭ 291 (-5.52%)
Mutual labels:  unity, unity3d
Libplanet
Blockchain core in C#/.NET for persistent peer-to-peer online games
Stars: ✭ 293 (-4.87%)
Mutual labels:  unity, unity3d
Unity Script Collection
A maintained collection of useful & free unity scripts / library's / plugins and extensions
Stars: ✭ 3,640 (+1081.82%)
Mutual labels:  unity, unity3d
Ecsrx
A reactive take on the ECS pattern for .net game developers
Stars: ✭ 288 (-6.49%)
Mutual labels:  unity, unity3d
Mapssdk Unity
This repository contains samples, documentation, and supporting scripts for Maps SDK, a Microsoft Garage project.
Stars: ✭ 307 (-0.32%)
Mutual labels:  unity, unity3d
Framework
deprecated, use : https://github.com/CatLib/CatLib
Stars: ✭ 279 (-9.42%)
Mutual labels:  unity, unity3d
Knight
Knight is a game framework based on Unity3D engine. It includes a complete assetbundle manager, a c# hotfix module based on ILRuntime, and a UI module based on MVVM, and other basic functions support.
Stars: ✭ 302 (-1.95%)
Mutual labels:  unity, unity3d
Proceduralmotiontrack
Simple procedural motion with Unity Timeline.
Stars: ✭ 300 (-2.6%)
Mutual labels:  unity, unity3d
Liquidsimulator
Cellular Automaton 2D Liquid Simulator for Unity
Stars: ✭ 302 (-1.95%)
Mutual labels:  unity, unity3d
Discord Rpc Csharp
C# custom implementation for Discord Rich Presence. Not deprecated and still available!
Stars: ✭ 282 (-8.44%)
Mutual labels:  unity, unity3d
Savegamefree
Save Game Free is a free and simple but powerful solution for saving and loading game data in unity.
Stars: ✭ 279 (-9.42%)
Mutual labels:  unity, unity3d
Tutorial 2d Game Unity
Unity tutorial to learn how to make a complete 2D Shoot'em Up
Stars: ✭ 290 (-5.84%)
Mutual labels:  unity, unity3d
Realtime Csg For Unity
Realtime-CSG, CSG level editor for Unity
Stars: ✭ 281 (-8.77%)
Mutual labels:  unity, unity3d
Unity Destruction
💥 An open-source script to destroy objects realistically in Unity3D.
Stars: ✭ 291 (-5.52%)
Mutual labels:  unity, unity3d
Unitygraphicsprogramming
書籍「UnityGraphicsProgramming vol.1」のサンプルコードリポジトリ
Stars: ✭ 321 (+4.22%)
Mutual labels:  unity, unity3d
Hisocket
It is a lightweight client socket solution, you can used it in C# project or Unity3d
Stars: ✭ 275 (-10.71%)
Mutual labels:  unity, unity3d
Solid
Книга о принципах объектно-ориентированного дизайна SOLID
Stars: ✭ 280 (-9.09%)
Mutual labels:  dependency-injection, di

VContainer

Releases openupm

The extra fast DI (Dependency Injection) library running on Unity Game Engine.

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

  • Fast Resolve: Basically 5-10x faster than Zenject.
  • Minimum GC Allocation: In Resolve, we have zero allocation without spawned instances.
  • Small code size: Few internal types and few .callvirt.
  • Assisting correct DI way: Provides simple and transparent API, and carefully select features. This prevents the DI declaration from becoming overly complex.
  • Immutable Container: Thread safety and robustness.

Features

  • Constructor Injection / Method Injection / Property & Field Injection
  • Dispatch own PlayerLoopSystem
  • Flexible scoping
    • Application can freely create nested Lifetime Scope with any async way for you like.
  • Pre IL Code generation optimization mode
  • UniTask Integration
  • ECS Integration beta

Performance

GC Alloc Result Example

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
    • "jp.hadashikick.vcontainer": "https://github.com/hadashiA/VContainer.git?path=VContainer/Assets/VContainer#1.6.0",
      
  3. UPM should now install the package.

Install via OpenUPM

  1. The package is available on the openupm registry. It's recommended to install it via 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
    • "com.unity.nuget.mono-cecil": "1.10.1",
      
  3. Download the .unitypackage from releases page.
  4. Open VContainer.x.x.x.unitypackage

Basic Usage

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

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

public interface IRouteSearch
{
}

public class AStarRouteSearch : IRouteSearch
{
}

public class CharacterService
{
    readonly IRouteSearch routeSearch;

    public CharacterService(IRouteSearch routeSearch)
    {
        this.routeSearch = routeSearch;
    }
}
public class ActorsView : MonoBehaviour
{
}

and

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.
    }
}
  • In this example, the routeSearch of CharacterService is automatically set as the instance of AStarRouteSearch when CharacterService is resolved.
  • Further, VContainer can have a Pure C# class as an entry point. (Various timings such as Start, Update, etc. can be specified.) 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.

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.

class SceneLoader
{
    readonly LifetimeScope currentScope;

    public SceneLoader(LifetimeScope currentScope)
    {
        this.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);
        }
    }
}
// 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..
}

UniTask

public class FooController : IAsyncStartable
{
    public async UniTask StartAsync(CancellationToken cancellation)
    {
        await LoadSomethingAsync(cancellation);
        await ...
        ...
    }
}
builder.RegisterEntryPoint<FooController>(Lifetime.Scoped);

Documentation

Visit vcontainer.hadashikick.jp to view the full documentation.

Getting Started

Visit vcontainer.hadashikick.jp/getting-started to get started.

Credits

VContainer is inspired by:

Author

@hadashiA

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].