Skip to content

Commit dac3b2e

Browse files
committed
Merge branch 'master' of http://github.com/cleavetv/unity-framework into architect_framework_impl
2 parents 9995673 + f880cba commit dac3b2e

File tree

9 files changed

+72
-32
lines changed

9 files changed

+72
-32
lines changed

Assets.meta

Lines changed: 0 additions & 5 deletions
This file was deleted.

CleaveFramework.unitypackage

-121 KB
Binary file not shown.

CleaveFramework.unitypackage.meta

Lines changed: 0 additions & 4 deletions
This file was deleted.

Docs.meta

Lines changed: 0 additions & 5 deletions
This file was deleted.

Docs/InjectorObject.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ We can inject into a C# object like:
1818
```
1919
Note: Injecting into MonoBehaviours is perfectly valid however you must Inject as a Field only. Attempting to Inject a Property into a MonoBehaviour will compile but throw an exception at runtime.
2020

21+
### Templated Injection
22+
[Inject] also supports templated values, which is a value or reference type associated to a string instead of a System.Type. You can define a field or property to be injected with a template like so:
23+
```csharp
24+
[Inject("IsFoo")] public bool HasFoo {get; set;}
25+
```
26+
2127
## Injection Types
22-
Injection of two different variable types is supported: Singleton and Transient.
28+
Injection of three different variable types is supported: Singleton, Transient, and Template.
2329

2430
The difference between a singleton and a transient is when you define a singleton you give it an instance of an object but when you define a transient you give it a type of an object. The injector will then assign either the instance of the singleton or create a brand new instance of that transient type when it injects, depending on what was requested.
2531

32+
A Template is an instance of an object bound to a string, not any type, interface, or concrete. Template injection can be useful if you need to inject default values or objects that may change based on exterior circumstances like a configuration file or application state.
33+
2634
Transient types can define default constructors through the Factory just like any other object which will be run before injection takes place.
2735

2836
### Singleton types:
@@ -41,7 +49,7 @@ Injector.BindSingleton<FooSystem>(myFooSystem);
4149
### Transient types:
4250
To use a transient type we use the Injector to map a type to an implementation. A type can be a concrete implementation type or an interface.
4351

44-
##### Give the injector a transient type:
52+
##### Give the Injector a transient type:
4553
```csharp
4654
// if we don't implement any interface we can just give it the type.
4755
// Any object looking to inject FooSystem will receive a new FooSystem()
@@ -51,14 +59,26 @@ Injector.BindTransient<FooSystem>();
5159
Injector.BindTransient<IFooSystem, FooSystemImpl>();
5260
```
5361

62+
### Template types:
63+
To use a template type we use the Injector to map a string to an instance or value. Any value or reference type can be bound to a template.
64+
65+
##### Give the Injector a template:
66+
```csharp
67+
Injector.BindTemplate("IsFoo", true);
68+
```
69+
70+
Note I'm using bool here as a simple example but you can use this to bind any instance. Attempting to assign into to something that can't be implicitly casted from the target will cause an assertion at runtime.
71+
5472
##### Define an object that injects a FooSystem:
5573
```csharp
5674
// define our object
5775
class ObjectA : IInitializable {
5876
// precede injectable types with the [Inject] attribute
5977
[Inject] public IFooSystem AFooSystem {get; set;} // Field or Property injection is valid here
78+
[Inject("IsFoo")] public bool HasFoo {get; set;}
6079
void Initialize() {
61-
AFooSystem.SomeMethod(); // AFooSystem is resolved here already assuming ObjectA was created by Factory
80+
if(HasFoo) // this is true because of templated injection
81+
AFooSystem.SomeMethod(); // AFooSystem is resolved here already assuming ObjectA was created by Factory
6282
}
6383
}
6484
```
@@ -70,7 +90,9 @@ var myA = Factory.Create<ObjectA>(ConstructObjectA);
7090
object ConstructObjectA(object obj)
7191
{
7292
var objA = obj as ObjectA;
73-
objA.AFooSystem.SomeMethod(); // AFooSystem is resolved here already and we can use it if we need to
93+
if(objA.HasFoo) // This is true because of templated injection
94+
objA.AFooSystem.SomeMethod(); // AFooSystem is resolved here already and we can use it if we need to
95+
7496
return objA;
7597
}
7698
```

Docs/SceneObjectDataObject.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SceneObjectData
22

3-
The SceneObjectData is a container for objects created at runtime. The container is what provides the invocation of the framework [Interfaces](Interfaces.md) available so any object you want to have the interface methods automatically invoked on needs to be inside of a SceneObjectData container.
3+
The SceneObjectData is a container for objects created at runtime. The container is what provides the invocation of the framework [Interfaces](Interfaces.md) available so any object you want to have the interface methods automatically invoked on needs to be inside of an initialized, updating, and destroyed SceneObjectData container. This is done behind the scenes for the `SceneView` instance of SceneObjectData but it's important to note in case you want to reuse this object elsewhere.
44

55
## `InitializeSceneObjects()`
66

@@ -18,13 +18,14 @@ Calling `Update(deltaTime)` on the SceneObjectData instance will invoke the `Upd
1818

1919
Calling `Destroy()` on the SceneObjectData will invoke the `Destroy()` method on all contained objects implementing the `IDestroyable` interface. It will also clear all the containers and reset the initialization state of the object to false allowing you to re-use it with new object data if you want to.
2020

21-
## SceneDataObject contained object types
21+
## Example code
2222

2323
For the following examples assume we have access to a SceneObjectData defined like:
2424
```csharp
2525
public SceneObjectData SceneObjects;
2626
```
2727

28+
2829
### Singleton
2930

3031
A SceneObjects Singleton type is a 1-to-1 mapping of a System.Type to an instance of that type.
@@ -59,6 +60,8 @@ for(var i = 0; i < 5; i++) {
5960
```
6061

6162
#### Resolve a transient
63+
64+
##### By Name:
6265
```csharp
6366
// resolve instances of Foo named Foo0 through Foo4
6467
List<Foo> fooList = new List<Foo>();
@@ -67,3 +70,36 @@ for(var i = 0; i < 5; i++) {
6770
}
6871
```
6972

73+
##### By Type:
74+
```csharp
75+
// return every transient object of type Foo found in the data and map it's name to it's instance
76+
KeyValuePair<string, object> [] foosArray = SceneObjects.ResolveTransient<Foo>();
77+
```
78+
79+
### Removing Objects from the data
80+
81+
Upon removal of the object from the data `Destroy()` will be invoked on the object before it is returned.
82+
83+
Depending on the type the technique to remove the data varies:
84+
85+
#### Removing Singletons
86+
87+
A singleton can be removed or replaced by simply binding over it with another instance of the same object type or by binding it to `null`. Obviously no object will be returned here so be sure to cache the reference or destruct it properly before binding over it. For example:
88+
89+
```csharp
90+
var oldFoo = SceneObjects.ResolveSingleton<IFoo>();
91+
FoosFriends.SayGoodbye(oldFoo);
92+
var newFoo = SceneObjects.PushSingleton<IFoo>(new DifferentFooImpl()); // oldFoo.Destroy() method was invoked now
93+
FoosFriends.SayHello(newFoo);
94+
```
95+
96+
#### Removing Transients
97+
98+
A transient can be removed by calling `PopTransient<T>(string ...)` on the SceneObjectData. For example:
99+
100+
```csharp
101+
// pop an object of type People named "Jeff" out of the data:
102+
var jeff = SceneObjects.PopTransient<People>("Jeff"); // jeff.Destroy() was invoked now
103+
```
104+
105+

LICENSE.meta

Lines changed: 0 additions & 4 deletions
This file was deleted.

Readme.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
# CleaveFramework v0.2.2
1+
# CleaveFramework v0.2.4
22

33
A Unity3D C# application framework.
44

55
## Quick Feature Overview
66

77
* Unity Scene Management
88
- Transitional Loading Scenes
9-
* C# Object Management with modular Interface support
9+
* POCO Object Management with modular Interface support
1010
- Global Objects
1111
* Resolve object instances across your entire application in any scene or class
1212
- Scene Objects
1313
* Resolve scene specific object instances in any class
14-
- Automatically Update Objects
15-
* Object Manager takes care of updating objects that require it for you. Stops you from creating general objects specifically to manage other objects.
14+
- Reusable object container
15+
* Add, remove, or resolve objects of any type at any time.
16+
* Automatically initialize, update, and destroy objects.
1617
* Object Creation Factory supports C# Objects and Unity Component Attachments
1718
- Attach Constructors to MonoBehaviour Components
1819
* Automated Dependency Injection Module
20+
- Supports Field or Property injection into POCOs or MonoBehaviours
21+
* Bind interfaces to implementations
22+
* Binding of templated value or reference types to parameterized members
1923
* Global Application level Executable Command Queuing System
2024
- Reuse the Command Framework and Executable Command Queue Object in your own implementations with minimal code.
2125
* Private Command Subscription for Multi-Delegate Callbacks

Readme.md.meta

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)