StrangeIoC
0.6.0
The IoC/Binding Framework for Unity3D and C#
|
The recommended Context for getting the most out of StrangeIoC. More...
Public Member Functions | |
MVCSContext (MonoBehaviour view) | |
The recommended Constructor Just pass in the instance of your ContextView. More... | |
MVCSContext (MonoBehaviour view, ContextStartupFlags flags) | |
MVCSContext (MonoBehaviour view, bool autoMapping) | |
override IContext | SetContextView (object view) |
Set the object that represents the top of the Context hierarchy. More... | |
override void | Launch () |
Fires ContextEvent.START Whatever Command/Sequence you want to happen first should be mapped to this event. More... | |
override object | GetComponent< T > () |
Gets an instance of the provided generic type. More... | |
override object | GetComponent< T > (object name) |
Gets an instance of the provided generic type and name from the InjectionBinder Always bear in mind that doing this risks adding dependencies that must be cleaned up when Contexts are removed. More... | |
override void | AddView (object view) |
Register a View with this Context. | |
override void | RemoveView (object view) |
Remove a View from this Context. | |
override void | OnRemove () |
Clean up. Called by a ContextView in its OnDestroy method. | |
Public Member Functions inherited from strange.extensions.context.impl.CrossContext | |
CrossContext (object view) | |
CrossContext (object view, ContextStartupFlags flags) | |
CrossContext (object view, bool autoMapping) | |
override IContext | AddContext (IContext context) |
Add another Context to this one. | |
virtual void | AssignCrossContext (ICrossContextCapable childContext) |
Add cross-context functionality to a child context being added. | |
virtual void | RemoveCrossContext (ICrossContextCapable childContext) |
Clean up cross-context functionality from a child context being removed. | |
override IContext | RemoveContext (IContext context) |
Remove a context from this one. | |
Public Member Functions inherited from strange.extensions.context.impl.Context | |
Context (object view, ContextStartupFlags flags) | |
Context (object view) | |
Context (object view, bool autoMapping) | |
virtual object | GetContextView () |
Get the ContextView. | |
virtual IContext | Start () |
Call this from your Root to set everything in action. | |
Public Member Functions inherited from strange.framework.impl.Binder | |
delegate void | BindingResolver (IBinding binding) |
A handler for resolving the nature of a binding during chained commands. | |
virtual IBinding | Bind< T > () |
Bind a Binding Key to a class or interface generic. | |
virtual IBinding | Bind (object key) |
Bind a Binding Key to a value. | |
virtual IBinding | GetBinding< T > () |
Retrieve a binding based on the provided Type. | |
virtual IBinding | GetBinding (object key) |
Retrieve a binding based on the provided object. | |
virtual IBinding | GetBinding< T > (object name) |
Retrieve a binding based on the provided Key (generic)/Name combo. | |
virtual IBinding | GetBinding (object key, object name) |
Retrieve a binding based on the provided Key/Name combo. | |
virtual void | Unbind< T > () |
Remove a binding based on the provided Key (generic) | |
virtual void | Unbind (object key) |
Remove a binding based on the provided Key. | |
virtual void | Unbind< T > (object name) |
Remove a binding based on the provided Key (generic) / Name combo. | |
virtual void | Unbind (object key, object name) |
Remove a binding based on the provided Key / Name combo. | |
virtual void | Unbind (IBinding binding) |
Remove the provided binding from the Binder. | |
virtual void | RemoveValue (IBinding binding, object value) |
Remove a select value from the given binding. | |
virtual void | RemoveKey (IBinding binding, object key) |
Remove a select key from the given binding. | |
virtual void | RemoveName (IBinding binding, object name) |
Remove a select name from the given binding. | |
virtual IBinding | GetRawBinding () |
Generate an unpopulated IBinding in whatever concrete form the Binder dictates. | |
virtual void | ResolveBinding (IBinding binding, object key) |
This method places individual Bindings into the bindings Dictionary as part of the resolving process. More... | |
Protected Member Functions | |
override void | addCoreComponents () |
Map the relationships between the Binders. More... | |
override void | instantiateCoreComponents () |
Override to instantiate componentry. Or just extend MVCSContext. | |
override void | postBindings () |
Override to do things after binding but before app launch. | |
virtual void | cacheView (MonoBehaviour view) |
Caches early-riser Views. More... | |
virtual void | mediateViewCache () |
Provide mediation for early-riser Views. | |
Static Protected Attributes | |
static ISemiBinding | viewCache = new SemiBinding() |
A list of Views Awake before the Context is fully set up. | |
Properties | |
ICommandBinder | commandBinder [get, set] |
A Binder that maps Events to Commands. | |
IEventDispatcher | dispatcher [get, set] |
A Binder that serves as the Event bus for the Context. | |
IMediationBinder | mediationBinder [get, set] |
A Binder that maps Views to Mediators. | |
IImplicitBinder | implicitBinder [get, set] |
ISequencer | sequencer [get, set] |
A Binder that maps Events to Sequences. | |
Properties inherited from strange.extensions.context.impl.CrossContext | |
ICrossContextInjectionBinder | injectionBinder [get, set] |
A Binder that handles dependency injection binding and instantiation. | |
virtual IDispatcher | crossContextDispatcher [get, set] |
virtual IBinder | crossContextBridge [get, set] |
Properties inherited from strange.extensions.context.impl.Context | |
object | contextView [get, set] |
The top of the View hierarchy. More... | |
Properties inherited from strange.extensions.context.api.ICrossContextCapable | |
ICrossContextInjectionBinder | injectionBinder [get, set] |
All cross-context capable contexts must implement an injectionBinder. | |
IDispatcher | crossContextDispatcher [get, set] |
Set and get the shared system bus for communicating across contexts. | |
Additional Inherited Members | |
Public Attributes inherited from strange.extensions.context.impl.Context | |
bool | autoStartup |
If false, the Launch() method won't fire. | |
Static Public Attributes inherited from strange.extensions.context.impl.Context | |
static IContext | firstContext |
In a multi-Context app, this represents the first Context to instantiate. | |
Protected Attributes inherited from strange.extensions.context.impl.CrossContext | |
IEventDispatcher | _crossContextDispatcher |
A specific instance of EventDispatcher that communicates across multiple contexts. More... | |
The recommended Context for getting the most out of StrangeIoC.
By extending this Context, you get the entire all-singing/all-dancing version of Strange, as it was shipped from the warehouse and ready for you to map your dependencies.
As the name suggests, MVCSContext provides structure for app development using the classic MVC (Model-View-Controller) design pattern, and adds 'S' (Service) for asynchronous calls outside the application. Strange is highly modular, so you needn't use MVCSContext if you don't want to (you can extend Context or CrossContext directly) but MVCS is a highly proven design strategy and MVCSContext is by far the easiest way to get familiar with what Strange has to offer.
The parts:
contextView
The GameObject at the top of your display hierarchy. Attach a subclass of ContextView to a GameObject, then instantiate a subclass of MVCSContext to start the app.
Example:
public class MyProjectRoot : ContextView { void Awake() { context = new MyContext(this); //Extends MVCSContext } }
The contextView is automatically injected into all Mediators and available for injection into commands like so:
[Inject(ContextKeys.CONTEXT_VIEW)] public GameObject contextView{get;set;}
It is strongly advised that the contextView NOT be injected into Views, Models or Services.
injectionBinder
Maps dependencies to concrete classes or values.
Examples:
injectionBinder.Bind<ISpaceship>().To<TieFighter>(); //Injects a new TieFighter wherever an ISpaceship is requested injectionBinder.Bind<ISpaceship>().To<Starship>().ToName(Ships.ENTERPRISE); //Injects a Starship wherever an ISpaceship is requested with the Name qualifier Enterprise injectionBinder.Bind<ITool>().To<SonicScrewdriver>().ToSingleton(); //Injects SonicScrewdriver as a Singleton wherever an ITool is requested injectionBinder.Bind<IMoonbase>().ToValue(new Alpha()); //Injects the provided instance wherever IMoonbase is requested injectionBinder.Bind<ISpaceship>().Bind<ITimeShip>.To<Tardis>(); //Injects a new Tardis wherever EITHER ISpaceship or ITimeship is requested.
injectionBinder
is automatically injected into all commands and may be injected elsewhere with:
[Inject] public IInjectionBinder injectionBinder{ get; set;}
dispatcher
The event bus shared across the context. Informs listeners and triggers commands.
dispatcher
is injected into all EventMediators, EventCommands and EventSequenceCommands, and may be injected elsewhere with:
[Inject(ContextKeys.CONTEXT_DISPATCHER)] public IEventDispatcher dispatcher{ get; set;}
For examples, see IEventDispatcher. Generally you don't map the dispatcher's events to methods inside the Context. Rather, you map Commands and Sequences. Read on!
crossContextDispatcher
A second event bus for sending events between contexts. It should only be accessed from Commands or SequenceCommands, into which it may be injected by declaring the dependency:
[Inject(ContextKeys.CROSS_CONTEXT_DISPATCHER)] public IEventDispatcher dispatcher{ get; set;}
commandBinder
Maps events that result in the creation and execution of Commands. Events from dispatcher can be used to trigger Commands.
commandBinder
is automatically injected into all Commands.
Examples:
commandBinder.Bind(GameEvent.MISSILE_HIT).To<MissileHitCommand>(); //MissileHitCommand fires whenever MISSILE_HIT is dispatched commandBinder.Bind(GameEvent.MISSILE_HIT).To<IncrementScoreCommand>().To<UpdateServerCommand>(); //Both Commands fire commandBinder.Bind(ContextEvent.START).To<StartCommand>().Once(); //StartCommand fires when START fires, then unmaps itself
sequencer
Maps events that result in the creation and execution of Sequences, which are just like Commands, except they run sequentially, rather than in parallel.
'sequencer' is automatically injected into all SequenceCommands.
In the following example, TestMissileHitCommand
runs logic to determine whether the missile hit is valid. If it's not, it may call BreakSeqeunce()
. so neither of the other Commands will fire.
sequencer.Bind(GameEvent.MISSILE_HIT).To<TestMissileHitCommand>().To<IncrementScoreCommand>().To<UpdateServerCommand>();
mediationBinder
Maps Views to Mediators in order to insultate Views from direct linkage to the application.
MediationBinder isn't automatically injected anywhere. It is possible, however, that you might want to change mediation bindings at runtime. This might prove difficult as a practical matter, but if you want to experiment, feel free to inject mediationBinder
into Commands or SequenceCommands like so:
[Inject] IMediationBinder mediationBinder{get;set;}
Example:
mediationBinder.Bind<RobotView>().To<RobotMediator>();
|
inline |
The recommended Constructor Just pass in the instance of your ContextView.
Everything will begin automatically. Other constructors offer the option of interrupting startup at useful moments.
|
inlineprotectedvirtual |
Map the relationships between the Binders.
Although you can override this method, it is recommended that you provide all your application bindings in mapBindings()
.
Reimplemented from strange.extensions.context.impl.CrossContext.
|
inlineprotectedvirtual |
Caches early-riser Views.
If a View is on stage at startup, it's possible for that View to be Awake before this Context has finished initing. cacheView()
maintains a list of such 'early-risers' until the Context is ready to mediate them.
|
inline |
Gets an instance of the provided generic type.
Always bear in mind that doing this risks adding dependencies that must be cleaned up when Contexts are removed.
Implements strange.extensions.context.api.ICrossContextCapable.
|
inline |
Gets an instance of the provided generic type and name from the InjectionBinder Always bear in mind that doing this risks adding dependencies that must be cleaned up when Contexts are removed.
Implements strange.extensions.context.api.ICrossContextCapable.
|
inlinevirtual |
Fires ContextEvent.START Whatever Command/Sequence you want to happen first should be mapped to this event.
Reimplemented from strange.extensions.context.impl.Context.
|
inlinevirtual |
Set the object that represents the top of the Context hierarchy.
In MVCSContext, this would be a GameObject.
Reimplemented from strange.extensions.context.impl.Context.