StrangeIoC
0.6.0
The IoC/Binding Framework for Unity3D and C#
|
Interface for the Binder which maps Views to Mediators. More...
Public Member Functions | |
void | Trigger (MediationEvent evt, IView view) |
An event that just happened, and the View it happened to. More... | |
IMediationBinding | BindView< T > () |
Porcelain for Bind<T> providing a little extra clarity and security. | |
Public Member Functions inherited from strange.framework.api.IBinder | |
IBinding | Bind< T > () |
Bind a Binding Key to a class or interface generic. | |
IBinding | Bind (object value) |
Bind a Binding Key to a value. | |
IBinding | GetBinding< T > () |
Retrieve a binding based on the provided Type. | |
IBinding | GetBinding (object key) |
Retrieve a binding based on the provided object. | |
IBinding | GetBinding< T > (object name) |
Retrieve a binding based on the provided Key (generic)/Name combo. | |
IBinding | GetBinding (object key, object name) |
Retrieve a binding based on the provided Key/Name combo. | |
IBinding | GetRawBinding () |
Generate an unpopulated IBinding in whatever concrete form the Binder dictates. | |
void | Unbind< T > () |
Remove a binding based on the provided Key (generic) | |
void | Unbind< T > (object name) |
Remove a binding based on the provided Key (generic) / Name combo. | |
void | Unbind (object key) |
Remove a binding based on the provided Key. | |
void | Unbind (object key, object name) |
Remove a binding based on the provided Key / Name combo. | |
void | Unbind (IBinding binding) |
Remove the provided binding from the Binder. | |
void | RemoveValue (IBinding binding, object value) |
Remove a select value from the given binding. | |
void | RemoveKey (IBinding binding, object value) |
Remove a select key from the given binding. | |
void | RemoveName (IBinding binding, object value) |
Remove a select name from the given binding. | |
void | OnRemove () |
The Binder is being removed Override this method to clean up remaining bindings. | |
void | ResolveBinding (IBinding binding, object key) |
Places individual Bindings into the bindings Dictionary as part of the resolving process More... | |
Interface for the Binder which maps Views to Mediators.
In a general sense, mediation is the act of using one thing to separate and communicate between two others. mediation in Strange refers to separating Views from the rest of the application. The reason for doing this is not at all theoretical, but highly practical. Views ypically come in two flavors: the "component", which tends to be stable and dropped into multiple, highly varied situations, and the highly volatile "working" View, which changes rapidly according to last-minute design considerations. In both cases, Mediators help you to insulate the View from the app around it, and vice-versa. This yields components that are easier to re-use, and working Views whose chaos is structurally contained.
The MediationBinder quite simply Binds two (or more) classes. The Key is the View class, the Value is one or more Mediators. Whenever the View shows up, a corresponding Mediator joins it to buffer View from app. The View doesn't know about the Mediator, nor about the app beyond it. It simply establishes its API and waits tp be told what to do. The Mediator, on the other hand, is allowed to know quite a lot about the View and the app. It can be injected, it has access to the common event bus, and can listen for and Dispatch events. It is intended to be 'thin', that is, it should know just enough to provide mediation. Leave logic, data storage, and View behaviour to other classes.
In the context of Unity3D, the View is a MonoBehaviour attached to a GameObject. The mediator is also a MonoBehaviour, so it has access to all the usual things a MomoBehaviour would. Consider it a best practice to attach only the View to your GameObject in Unity3D.
Finally, two words of warning. First: Views may be injected. This allows you to provide a local Dispatcher, a Configuration file, or other items that might come in handy. I recommend very strongly that you do not inject the context-wide Dispatcher, nor any other class involving the world beyond the View's immediate area of interest. To do so risks negating the whole point of mediation.
Second: experience tells me that understanding what belongs in Mediator and what in View is the trickiest part of this system. I recommend the 'thin' class approach, i.e., nothing goes in the Mediator but what it needs to mediate.
void strange.extensions.mediation.api.IMediationBinder.Trigger | ( | MediationEvent | evt, |
IView | view | ||
) |
An event that just happened, and the View it happened to.
If the event was Awake, it will trigger creation of a mapped Mediator.
Implemented in strange.extensions.mediation.impl.MediationBinder.