Git Product home page Git Product logo

zenject-instancebroker's Introduction

Zenject InstanceBroker

Publish and receive some instances what spawned after resolving phase.

Installation

upm add package dev.monry.zenject-instancebroker

Note: upm is command line interface for Unity Package Manager

Usages

Prepare

Add reference to Zenject.InstanceBroker.asmdef in your project's asmdef.

Bind types and Declare signals

using Zenject;

public class SampleInstaller : Installer<SampleInstaller>
{
    public override void InstallBindings()
    {
        Container.DeclareBrokableInstance<PublishSample>();
    }
}

DiContainer.DeclareBrokableInstance<T>() binds types and declare signals.

  • Bind below types
    • IInstancePublisher<T>
    • IInstanceReceiver<T>
  • Declare signal of T

Publish

using UnityEngine;
using Zenject;

public class Sample : MonoBehaviour
{
    [Inject] private IInstancePublisher<Sample> Publisher { get; }

    [Inject]
    private void Initialize()
    {
        Publisher.Publish(this);
    }
    
    public void Foo()
    {
        Debug.Log("Foo");
    }
}

Invoke IInstancePublisher<T>.Publish() after constructed.

Receive

using Zenject;
using UniRx;

public class ReceiveSample : IInitializable
{
    [Inject] private IInstanceReceiver<Sample> Receiver { get; }
    
    public void Initialize()
    {
        Receiver.Receive().Subscribe(x => x.Foo()); 
    }
}

Will stream instance of Sample when instantiated it.

ZenjectInstancePublisher

ZenjectInstancePublisher

Invoke IInstancePublisher<T>.Publish() automatically according to the settings of ZenjectBinding.

  1. Attach ZenjectInstancePublisher to a GameObject that contains the Component you want to publish
  2. Drag & Drop Component you want to publish into Components field on ZenjectBinding
  3. You can limit the scope in which instances are exchanged using Context field of ZenjectBinding
  4. Change Bind Type field of ZenjectBinding if you want to publish other than instance of Component itself such as interface

zenject-instancebroker's People

Contributors

monry avatar

Watchers

James Cloos avatar  avatar

zenject-instancebroker's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.