和Keyle一起学StrangeIoc – Introduction

StrangeIoC 

Strange: the IoC framework for Unity

Strange attractors create predictable patterns, often in chaotic systems. 在混乱的系统中创造出一个可以预测的模式 .

Introduction

StrangeIoc主要用于C#与Unity3d,我们已经在IOS,Web,Android项目中成功运用,他包含了如下功能,其中大部分功能都是可选的

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.

    依赖注入

    1.映射单例,每次都可通过工厂返回新实例

    2.类名注入

    3.属性器注入

    4.构造注入

    5.方法注入

    6.Monobehaviors注入

    7.绑定多态

    8.反射与绑定结合,减少反射的性能开销

  • Dependency Injection
    • Map as singleton, value or factory (get a new instance each time you need one)
    • Name injections
    • 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

    两种类型的事件共享总线

    1.二者的dispatch事件可在程序的任何一处调用

    2.二者为了实现本地通信都需要映射本地事件总线

    3.二者为了分离逻辑都需要映射事件

    4.新的Signals的实现增加了类型安全

  • Two styles of shared event bus.
    • Both dispatch events to any point in your application
    • Both map local event bus for local communication
    • Both map events to Command classes to separate business logic
    • The new Signals implementation adds type saftety
    • NB: Examples in this document use the default EventDispatcher. We've added a section explaining Signals, but didn't, frankly, have the patience to re-write the entire guide. Nevertheless, we encourage the use of Signals as the preferred means of communication.
  • 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

    介绍可选MVCS部分

    1.多上下文,在单独的功能中使用自身的上下文,全局功能中使用程序级上下文

    2.允许多个上下文之间通信

  • Multiple contexts
    • Allow subcomponents (separate Scenes) to function on their own, or in the context of larger apps.
    • Allow communication between contexts.
  • Don’t see what you need? The core binding framework is simple to extend. Build new Binders like:
    • A different type of dispatcher
    • 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.

 

posted @ 2015-02-14 23:35  keyle_xiao  阅读(691)  评论(0编辑  收藏  举报