sergeysychov / behaviour_inject Goto Github PK
View Code? Open in Web Editor NEWInversion of Control / Dependency Injection tool for Unity3d
License: MIT License
Inversion of Control / Dependency Injection tool for Unity3d
License: MIT License
If there are two components, and one of them is registered as dependency, other will not get events
Allow to create context in HierarchyContext component to contain events inside local hierarchy.
Instead create attribute parameter 'InheritEvents'
Sometimes there's a need for conditional context configuration, dependent on other contexts.
May be there should be another component ContextCreationInitalizer, that trigger context creation an allow to inject dependencies into context creator
Well i was looking up the project, you seem to have all the code, but not created scene, for autocompose and factory example. adding that would complete the tutorial
If pre-created dependency is regisetered multiple times as different interfaces, it's Dispose method will be called multiple times accordingly.
A a = Create(); _context = Context.Create(ContextNames.APPLICATION); _context .RegisterDependencyAs<A, B>(a) .RegisterDependencyAs<A, C>(a);
Make it possible to define default context for current scene. This will allow "use hirarchy" option to work even without hierarchy context component and avoid binding prefabs to particular contexts.
It would be like context.RegisterProxy<Foo, Bar>((foo) => foo.Bar)
think on methods of dependency aggregation into collections
In TransmitEvent add type check before InjectEventTo call.
Using OnContextDestroyed event causes additional memory allocation, wich might be significant if there are many objects.
Using RegisterAsMultiple may cause cycles remain uncatched.
Example stacktrace:
StackOverflowException: The requested operation caused a stack overflow.
System.RuntimeType.GetConstructors_internal (System.Reflection.BindingFlags bindingAttr, System.RuntimeType reflectedType) (at :0)
System.RuntimeType.GetConstructorCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConv, System.Type[] types, System.Boolean allowPrefixLookup) (at :0)
System.RuntimeType.GetConstructors (System.Reflection.BindingFlags bindingAttr) (at :0)
System.Type.GetConstructors () (at :0)
BehaviourInject.Context.FindAppropriateConstructor (System.Type resolvingType) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:419)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:391)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:376)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:361)
BehaviourInject.Context.Resolve (System.Type resolvingType) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:347)
BehaviourInject.Internal.AbstractInjecton.GetDependency (System.Type type, BehaviourInject.Context context) (at Assets/BInject/Scripts/BehaviourInject/IMemberInjection.cs:29)
BehaviourInject.Internal.MethodInjection.Inject (System.Object target, BehaviourInject.Context context) (at Assets/BInject/Scripts/BehaviourInject/IMemberInjection.cs:111)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:411)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:376)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:401)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:376)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:361)
BehaviourInject.Context.Resolve (System.Type resolvingType) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:347)
BehaviourInject.Internal.AbstractInjecton.GetDependency (System.Type type, BehaviourInject.Context context) (at Assets/BInject/Scripts/BehaviourInject/IMemberInjection.cs:29)
BehaviourInject.Internal.MethodInjection.Inject (System.Object target, BehaviourInject.Context context) (at Assets/BInject/Scripts/BehaviourInject/IMemberInjection.cs:111)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:411)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:376)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:401)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:376)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:361)
BehaviourInject.Context.Resolve (System.Type resolvingType) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:347)
BehaviourInject.Internal.AbstractInjecton.GetDependency (System.Type type, BehaviourInject.Context context) (at Assets/BInject/Scripts/BehaviourInject/IMemberInjection.cs:29)
BehaviourInject.Internal.MethodInjection.Inject (System.Object target, BehaviourInject.Context context) (at Assets/BInject/Scripts/BehaviourInject/IMemberInjection.cs:111)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:411)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
BehaviourInject.Context.TryResolve (System.Type resolvingType, System.Object& dependency, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:376)
BehaviourInject.Context.AutocomposeDependency (System.Type resolvingType, System.Int32 hierarchyDepthCount) (at Assets/BInject/Scripts/BehaviourInject/Context.cs:401)
BehaviourInject.Internal.SingleAutocomposeDependency.Resolve (BehaviourInject.Context context, System.Int32 depth) (at Assets/BInject/Scripts/BehaviourInject/IDependency.cs:67)
It would be usable to register type as more than just one dependency.
Should be like this
_context.RegisterAs<MyClass>(new Type{ typeof(Interface1), typeof(Interface2)... })
Add exception handler at MethodInjection invocation.
Allow to inject some params by it's names and type/member description.
I.e.
_context.RegisterParameter("playerId", "PlayerProfile.GetPlayerId")
If MonoBehaviour is both dependency and recipient (via Injector), it's event handlers will be called twice
Currently icons of Injector and HierarchyContext are visible on scene. Overload gizmo drawer to prevent it
lets say Foo is not registered as any dependency
than in following code
class Bar : MonoBehaviour{
[AutocomposeOnDemand]
//or
[Inject(CreateOnDemand = true)]
private Foo _foo;
}
_foo is filled with Foo instance immidiatly created by Context, without registering it
It's possible to find and init classes that implements IContextCreator and are marked by attribute containing name of the context
ReflectionCache.IsInjectible is called too often.
Need to reduce count of this calls and depth of members search
Default events is very hard to profile with unity, thus it shuld be changed to custom event pattern implementation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.