Skip to content

MonoBehaviour/Components injection issues #45

@josimard

Description

@josimard

Hi,
we had problems troubleshooting injection issues when requesting bindings with components.

Unity did throw some warning, but the stack made it hard to troubleshoot:

You are trying to create a MonoBehaviour using the 'new' keyword. [...]

An error should be implemented to help users pin-point the issue fast. The issue can happen often when using injection with components, either when component values are null or when the binding order is wrong.

I managed to implement an error message that greatly helps finding from which components are problematic:
josimard@21cab92

Ultimately, we did not find how to specify the injector not to instantiate some types... It was hard understand why we had multiple instances of our behaviors when using injection at first. We are not sure why the binding order is so important in our case...

This is how we bind component instances in our container:

container.Bind<T>().To(instance);

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions