Code Monkey home page Code Monkey logo

strangerocks's Introduction

Strange: the IoC framework for Unity3D and C#

Current version: v1.0.0

Website: http://strangeioc.github.io/strangeioc/

Strange attractors create predictable patterns, often in chaotic systems.

Strange is a super-lightweight and highly extensible Inversion-of-Control (IoC) framework, written specifically for C# and Unity. We've validated Strange on web, standalone, and iOS, and Android.

It contains the following features, most of which are optional:

  • A core binding framework that pretty much lets you bind one or more of anything to one or more of anything else.
  • Dependency Injection
    • Map as singleton, value or factory (get a new instance each time you need one)
    • Name injections and/or supply specific implementations to specific consumer classes
    • Perform constructor or setter injection
    • Tag your preferred constructor
    • Tag a method to fire after construction
    • Inject into MonoBehaviours
    • Bind polymorphically (bind any or all of your interfaces to a single concrete class)
  • Reflection binding dramatically reduces overhead of employing reflectivity
  • Two shared event bus systems, EventDispatcher and Signals. Both allow you to:
    • Dispatch events to any point in your application
    • Map local events for local communication
    • Map events to Commands classes to separate business logic
    • EventDispatcher transmits data payloads as primitives or ValueObjects
    • Signals transmits data in bindable, type-safe parameters
  • MonoBehaviour mediation
    • Facilitate separation of a view from the application using it
    • Keep Unity-specific code isolated from the rest of the app
  • Optional MVCS (Model/View/Controller/Service) structure
  • Multiple contexts
    • Allow subcomponents (separate Scenes) to function on their own, or in the context of larger apps.
    • Allow communication between contexts.
  • Promises
    • Similar to Javascript Q-Promises, these help control flow and error handling
    • Promises also fit some common signal use cases much more cleanly!
  • Annotated 'Implicit' Bindings
  • Reduce boiler plate code written in your Context and Mediators!
  • JSON-driven bindings
  • Dynamically load your bindings at runtime!
  • Don't see what you need? The core binding framework is simple to extend. Build new Binders like:
    • A different type of dispatcher, like AS3-Signals <- WAIT A MOMENT! WE DID EXACTLY THAT!!!
    • An entity framework
    • A multi-loader

In addition to organizing your project into a sensible structure, Strange offers the following benefits:

  • Designed to play well with Unity3D. Also designed to play well without it.
  • Separate UnityEngine code from the rest of your app.
    • Improves portability
    • Improves unit testability
  • A common event bus makes information flow easy and highly decoupled. (Note: Unity's SendMessage method does this, of course, but it's dangerous as all get-out. I may write a whole article on just this topic at some point.)
  • The extensible binder really is amazing (a friend used to tell me "it's good to like your own cookin'"). The number of things you can accomplish with the tiny core framework would justify Strange all on its own.
  • Multiple contexts allow you to "bootstrap" subcomponents so they operate fine either on their own or as an integrated part. This can hugely speed up your development process and allow developers to work in isolation, then integrate in later stages of development.
  • Get rid of platform-specific #IF...#ELSE constructs in your code. IoC allows you to write whole concrete implementations correctly, then bind the ones you want to use at compile time or at run time. (As with other forms of binding, #IF...#ELSE clauses can be isolated into a single class and away from the rest of your code.)

Supported Versions/Platforms

Strange works with Unity 3.5+. Click here to see the full list of supported runtime platforms.

Acknowledgements

It is hard to adequately credit the creators of the open source Actionscript framework RobotLegs for their influence on the creation of StrangeIoC. While Strange is not a port of RobotLegs, the ensigns of that library are copiously reflected throughout this one. For their great service to my professional development, I offer that team my sincerest thanks. And a donut. Seriously, if you're ever in town, let me buy you a donut.

Kudos to Will Corwin for picking up a thrown-down gauntlet and writing the Signals and Implicit Bindings implementations.

I also need to thank and congratulate the folks at ThirdMotion who inexplicably gave me time to build Strange and license to open source it.

/**********************************************/ Copyright 2013 ThirdMotion, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.

strangerocks's People

Contributors

fogandwhisky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

strangerocks's Issues

Visual tracers when I play in the editor

When I play strangerocks in the editor it looks like it isn't clearing the framebuffer or something. The Score and Level labels look overdrawn. All I see are tracers of the rocks and ships once I begin a level. I am on a mac running Unity3d 4.3.4f. Do I need to change some of the player settings or something?

No Tests?

The first things I was hungry to find out was how you setup your tests, so I was pretty disappointed to see no tests. I have only done a tiny bit of Unit Testing with Unity and I found NUnit and Rhino Mocks to be rather good for the job, but I was hoping to learn more from some people who are more seasoned writing tests an Unity. I'll fork the repo and add a test or two and you can let me know what you think.

Question: Is it good form to Dispatch a signal in a Model "setter" for poor man's Data Binding?

Hi, Thanks for all the great work on StrangeIoC so far! I'm part of an experienced dev team looking to make the switch from a proprietary in house engine to Unity, and Strange has really helped inform our architecture decisions.

I'm new to MVC and C# in general but I was wondering if it makes sense to hook a signal to a set method of a Model's property?

private int _score;
public int score 
{ 
   get { return _score; } 
   set 
   { 
       _score = value; 
      updateScoreSignal.Dispatch (_score); 
   } 
}

This seems simpler to me than having to remember call
updateScoreSignal.Dispatch (model.score); everytime I update the Model.score property.

Thoughts?

Null Binding issue

This may very well be something silly -- but copying the strangerocks scripts and the latest StrangeIoC sources, with Unity3d v.4.5.4 I'm getting null binding issues:

  • InjectionException: Attempt to Instantiate a null binding.
    target: strange.examples.strangerocks.game.KeyboardInput
    type: strange.examples.strangerocks.IRoutineRunner

I went around Debug.Logging various parts of Strange to see if there was anything obvious.

  • I noticed Binding.cs - Dictionary<> "bindings" has only 2 items in the KeyboardInput injection list: IEventDispatcher and CrossContextBridge
  • KeyboardInput inherits from IInput which is bound as: injectionBinder.Bind().To().ToSingleton ()
  • GameIndependentStartCommand injects IInput - which is supposed to instantiate the game input

If it makes any difference -- I'm also noticing 4 null binding errors in the UI scene as well: EndGamePanelView, IdlePanelView, StartLevelPanelView, and HUDView -- all blowing up on injecting IScreenUtil.

Has anyone else noticed this happening lately? Is this something obvious I'm doing wrong? Thanks.

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.