InjectExample.cs 437 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. namespace QFramework.Example
  3. {
  4. public class InjectExample : MonoBehaviour
  5. {
  6. [Inject] public A AObj;
  7. // Use this for initialization
  8. void Start()
  9. {
  10. var container = new QFrameworkContainer();
  11. container.RegisterInstance(new A());
  12. container.Inject(this);
  13. container.Resolve<A>().HelloWorld();
  14. }
  15. public class A
  16. {
  17. public void HelloWorld()
  18. {
  19. "This is A obj".LogInfo();
  20. }
  21. }
  22. }
  23. }