Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for inheriting MonoBehaviour bindings and injecting GameObject using FromComponentSibling() #300

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

suzdalnitski
Copy link

@suzdalnitski suzdalnitski commented Jul 12, 2017

  1. Added support for inheriting MonoBehaviour bindings (issue 294). To enable use Container.InheritMonoBehaviourBindings = true;

  2. Added support for injecting the current game object. It might be useful to inject the current GameObject as a property instead of using the built-in .gameObject reference. Usage example:
    Bind<GameObject>().FromComponentSibling()

  3. Added support for injecting static classes/members. Injecting static classes is useful for Unit Testing when using extension methods. To inject a static class from the installer:
    Container.QueueForInject(typeof(GameObjectExtensions));

To make an extension class mockable:

public static class GameObjectExtensions {
   [Inject]
   private static IGameObjectExtensions _extensionsImplementation;

   public static void MoveTo(this GameObject obj, Vector3 position)
                                          => _extensionsImplementation.Move(obj, position);
}

…onentInHierarchy. Usage example: Container.Bind<UIButton>().WithId("close").FromComponentInChildren(go => go.name == "close button");

- Added an option to include inactive objects to FromComponentInChildren and FromComponentInHierarchy.
- Added Resharper's [MeansImplicitUse] attribute to InjectOptionalAttribute.
C# 6.0 introduced a very useful feature - get-only properties, which is a great addition to dependency injection toolbox. C# 6.0 support is currently available in Unity unofficially, and official support is coming soon.

Usage example:
[Inject] private UIButton Button { get; }
…tainer.InheritMonoBehaviourBindings = true;

- Added support for binding current GameObject using FromComponentSibling()
…. This will allow to easily access the current MonoBehaviour context.

Example:
Bind<GameObject>().FromMethod(ctx => ctx.ToMonoBehaviourContext().gameObject);
+ Fixed InjectContext to work with non-Unity project
+ Added JetBrains.Annotations to the main project so we can mark the [Inject] attribute with [MeansImplicitUse]. This is useful in non-Unity projects.
…t to return Zenject MonoBehaviour contexts. This might happen if we bind Zenject interfaces (e.g. ITickable).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant