{"id":13663946,"url":"https://github.com/intentor/adic","last_synced_at":"2026-01-28T17:40:22.853Z","repository":{"id":27510671,"uuid":"30991339","full_name":"intentor/adic","owner":"intentor","description":"Lightweight dependency injection container for Unity","archived":false,"fork":false,"pushed_at":"2021-08-09T01:40:41.000Z","size":1320,"stargazers_count":196,"open_issues_count":13,"forks_count":29,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-11-10T21:39:32.781Z","etag":null,"topics":["discontinued","ioc","library","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/intentor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-18T22:49:31.000Z","updated_at":"2024-07-02T15:02:04.000Z","dependencies_parsed_at":"2022-09-01T02:40:47.359Z","dependency_job_id":null,"html_url":"https://github.com/intentor/adic","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intentor%2Fadic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intentor%2Fadic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intentor%2Fadic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intentor%2Fadic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/intentor","download_url":"https://codeload.github.com/intentor/adic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250890560,"owners_count":21503515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discontinued","ioc","library","unity"],"created_at":"2024-08-02T05:02:41.716Z","updated_at":"2026-01-28T17:40:22.825Z","avatar_url":"https://github.com/intentor.png","language":"C#","readme":"# ![Adic](https://cloud.githubusercontent.com/assets/5340818/6597415/4b95cb42-c7db-11e4-863f-9a284bfab310.png)\r\n\r\n***Another* Dependency Injection Container for Unity and beyond**\r\n\r\nCurrently the project is **DISCONTINUED**. However, feel free to fork it and continue its development!\r\n\r\n[![Unity Asset Store](https://cloud.githubusercontent.com/assets/5340818/6855739/9e14c9e0-d3d9-11e4-9171-594941ed056f.png)](https://assetstore.unity.com/packages/tools/adic-dependency-injection-container-32157) [![Donate](https://cloud.githubusercontent.com/assets/5340818/12418027/9434b3ea-be93-11e5-8395-253a3a1aade5.png)](http://donate.intentor.com.br/)\r\n\r\n## Contents\r\n\r\n1. \u003ca href=\"#introduction\"\u003eIntroduction\u003c/a\u003e\r\n2. \u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e\r\n3. \u003ca href=\"#concepts\"\u003eConcepts\u003c/a\u003e\r\n\t1. \u003ca href=\"#about-di\"\u003eAbout dependency injection (DI)\u003c/a\u003e\r\n\t\t1. \u003ca href=\"#what-is\"\u003eWhat is a DI container?\u003c/a\u003e\r\n\t\t2. \u003ca href=\"#why-use-it\"\u003eWhy use a DI container?\u003c/a\u003e\r\n\t\t3. \u003ca href=\"#why-use-with-unity\"\u003eWhy use it with Unity?\u003c/a\u003e\r\n\t\t4. \u003ca href=\"#common-use-cases\"\u003eCommon use cases\u003c/a\u003e\r\n\t\t5. \u003ca href=\"#further-readings\"\u003eFurther readings\u003c/a\u003e\r\n\t2. \u003ca href=\"#structure\"\u003eStructure\u003c/a\u003e\r\n\t3. \u003ca href=\"#types-of-bindings\"\u003eTypes of bindings\u003c/a\u003e\r\n\t4. \u003ca href=\"#namespace-conventions\"\u003eNamespace conventions\u003c/a\u003e\r\n\t5. \u003ca href=\"#chaining\"\u003eChaining\u003c/a\u003e\r\n4. \u003ca href=\"#quick-start\"\u003eQuick start\u003c/a\u003e\r\n5. \u003ca href=\"#api\"\u003eAPI\u003c/a\u003e\r\n\t1. \u003ca href=\"#bindings\"\u003eBindings\u003c/a\u003e\r\n\t2. \u003ca href=\"#constructor-injection\"\u003eConstructor injection\u003c/a\u003e\r\n\t4. \u003ca href=\"#member-injection\"\u003eMember injection\u003c/a\u003e\r\n\t3. \u003ca href=\"#method-injection\"\u003eMethod injection\u003c/a\u003e\r\n\t5. \u003ca href=\"#multiple-constructors\"\u003eMultiple constructors\u003c/a\u003e\r\n\t6. \u003ca href=\"#multiple-injection\"\u003eMultiple injection\u003c/a\u003e\r\n\t7. \u003ca href=\"#behaviour-injection\"\u003eBehaviour injection\u003c/a\u003e\r\n\t\t1. \u003ca href=\"#monobehaviour-injection\"\u003eMonoBehaviour injection\u003c/a\u003e\r\n\t\t2. \u003ca href=\"#statemachinebehaviour-injection\"\u003eStateMachineBehaviour injection\u003c/a\u003e\r\n\t\t3. \u003ca href=\"#scene-injection\"\u003eScene injection\u003c/a\u003e\r\n\t\t4. \u003ca href=\"#injecting-multiple-containers\"\u003eInjecting from multiple containers\u003c/a\u003e\r\n\t8. \u003ca href=\"#conditions\"\u003eConditions\u003c/a\u003e\r\n\t9. \u003ca href=\"#tags\"\u003eTags\u003c/a\u003e\r\n\t10. \u003ca href=\"#update\"\u003eUpdate\u003c/a\u003e\r\n\t11. \u003ca href=\"#dispose\"\u003eDispose\u003c/a\u003e\r\n\t12. \u003ca href=\"#instance-resolution-modes\"\u003eInstance resolution modes\u003c/a\u003e\r\n\t13. \u003ca href=\"#manual-type-resolution\"\u003eManual type resolution\u003c/a\u003e\r\n\t14. \u003ca href=\"#factories\"\u003eFactories\u003c/a\u003e\r\n\t15. \u003ca href=\"#bindings-setup\"\u003eBindings setup\u003c/a\u003e\r\n\t16. \u003ca href=\"#using-commands\"\u003eUsing commands\u003c/a\u003e\r\n6. \u003ca href=\"#multiple-scenes\"\u003eMultiple scenes\u003c/a\u003e\r\n7. \u003ca href=\"#order-of-events\"\u003eOrder of events\u003c/a\u003e\r\n8. \u003ca href=\"#script-execution-order\"\u003eScript execution order\u003c/a\u003e\r\n9. \u003ca href=\"#performance\"\u003ePerformance\u003c/a\u003e\r\n10. \u003ca href=\"#il2cpp-aot\"\u003eIL2CPP, AOT and code stripping\u003c/a\u003e\r\n11. \u003ca href=\"#general-notes\"\u003eGeneral notes\u003c/a\u003e\r\n12. \u003ca href=\"#container-extensions\"\u003eExtensions\u003c/a\u003e\r\n\t1. \u003ca href=\"#available-extensions\"\u003eAvailable extensions\u003c/a\u003e\r\n\t\t1. \u003ca href=\"#extension-bindings-printer\"\u003eBindings Printer\u003c/a\u003e\r\n\t\t1. \u003ca href=\"#extension-bindings-setup\"\u003eBindings Setup\u003c/a\u003e\r\n\t\t2. \u003ca href=\"#extension-commander\"\u003eCommander\u003c/a\u003e\r\n\t\t3. \u003ca href=\"#extension-context-root\"\u003eContext Root\u003c/a\u003e\r\n\t\t4. \u003ca href=\"#extension-event-caller\"\u003eEvent Caller\u003c/a\u003e\r\n\t\t5. \u003ca href=\"#extension-mono-injection\"\u003eMono Injection\u003c/a\u003e\r\n\t\t5. \u003ca href=\"#extension-state-injection\"\u003eState Injection\u003c/a\u003e\r\n\t\t6. \u003ca href=\"#extension-unity-binding\"\u003eUnity Binding\u003c/a\u003e\r\n\t2. \u003ca href=\"#creating-extensions\"\u003eCreating extensions\u003c/a\u003e\r\n\t3. \u003ca href=\"#container-events\"\u003eContainer events\u003c/a\u003e\r\n\t\t1. \u003ca href=\"#binder-events\"\u003eBinder events\u003c/a\u003e\r\n\t\t2. \u003ca href=\"#injector-events\"\u003eInjector events\u003c/a\u003e\r\n13. \u003ca href=\"#binaries\"\u003eBinaries\u003c/a\u003e\r\n14. \u003ca href=\"#examples\"\u003eExamples\u003c/a\u003e\r\n15. \u003ca href=\"#changelog\"\u003eChangelog\u003c/a\u003e\r\n16. \u003ca href=\"#support\"\u003eSupport\u003c/a\u003e\r\n17. \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\r\n\r\n## \u003ca id=\"introduction\"\u003e\u003c/a\u003eIntroduction\r\n\r\n*Adic* is a lightweight dependency injection container for Unity and any C# (or .Net) project.\r\n\r\nBased on the proof of concept container from [Sebastiano Mandalà](http://blog.sebaslab.com/ioc-container-for-unity3d-part-1/) and studies of [StrangeIoC](http://strangeioc.github.io/strangeioc/), the intention of the project is to create a dependency injection container that is simple to use and extend, having on its roots the simplicity of the work of Mandalà and the extensibility of StrangeIoC, also borrowing some ideas from the classic [Unity Application Block](https://unity.codeplex.com/).\r\n\r\nThe project is compatible with Unity 5 and 4. Tested on Windows/Mac/Linux, Android, iOS, WP10 (IL2CPP), Web Player and WebGL.\r\n\r\nAlso available on the [Unity Asset Store](https://www.assetstore.unity3d.com/en/#!/content/32157).\r\n\r\n## \u003ca id=\"features\"\u003e\u003c/a\u003eFeatures\r\n\r\n* Bind types, singleton instances, factories, game objects and prefabs.\r\n* Instance resolution by type, identifier and complex conditions.\r\n* Injection on constructor, fields and properties.\r\n* Can inject multiple objects of the same type.\r\n* Can inject on non public members.\r\n* Can resolve and inject instances from types that are not bound to the container.\r\n* Can inject automatically on components of a scene.\r\n* Fast dependency resolution with internal cache.\u003ca href=#performance\u003e\\*\u003c/a\u003e\r\n* Use of attributes to indicate injections, preferable constructors and post constructors.\r\n* Can be easily extended through extensions.\r\n* Framework decoupled from Unity - all Unity based API is achieved through extensions.\r\n* Organized and well documented code written in C#.\r\n\r\n## \u003ca id=\"concepts\"\u003e\u003c/a\u003eConcepts\r\n\r\n### \u003ca id=\"about-di\"\u003e\u003c/a\u003eAbout dependency injection (DI)\r\n\r\n#### \u003ca id=\"what-is\"\u003e\u003c/a\u003eWhat is a DI container?\r\n\r\nA *dependency injection container* is a piece of software that handles the resolution of dependencies in objects. It's related to the [dependency injection](http://en.wikipedia.org/wiki/Dependency_injection) and [inversion of control](http://en.wikipedia.org/wiki/Inversion_of_control) design patterns.\r\n\r\nThe idea is that any dependency an object may need should be resolved by an external entity rather than the own object. Practically speaking, an object should not use `new` to create the objects it uses, having those instances *injected* into it by another object whose sole existence is to resolve dependencies.\r\n\r\nSo, a *dependency injection container* holds information about dependencies (the *bindings*) that can be injected into another objects by demand (injecting into existing objects) or during resolution (when you are creating a new object of some type).\r\n\r\n#### \u003ca id=\"why-use-it\"\u003e\u003c/a\u003eWhy use a DI container?\r\n\r\nIn a nutshell, **to decouple your code**.\r\n\r\nA DI container, in pair with a good architecture, can ensure [SOLID principles](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29) and help you write better code.\r\n\r\nUsing such container, you can easily work with abstractions without having to worry about the specifics of each external implementation, focusing just on the code you are writing. It's all related to dependencies: any dependency your code needs is not resolved directly by your code, but externally, allowing your code to deal only with its responsibilities.\r\n\r\nAs a plus, there are other benefits from using a DI container:\r\n\r\n1. **Refactorability**: with your code decoupled, it's easy to refactor it without affecting the entire codebase.\r\n2. **Reusability**: thinking about abstractions allows your code to be even more reusable by making it small and focused on a single responsibility.\r\n3. **Easily change implementations**: given all dependencies are configured in the container, it's easy to change a implementation for a given abstraction. It helps e.g. when implementing generic functionality in a platform specific way.\r\n4. **Testability**: by focusing on abstractions and dependency injection, it's easy to replace implementations with mock objects to test your code.\r\n5. **Improved architecture**: your codebase will be naturally better and more organized because you'll think about the relationships of your code.\r\n6. **Staying sane**: by focusing on small parts of the code and having a consistent architecture, the sanity of the developer is also ensured!\r\n\r\n#### \u003ca id=\"why-use-with-unity\"\u003e\u003c/a\u003eWhy use it with Unity?\r\n\r\nUnity is not SOLID friendly out of the box. Even the official examples may give a wrong idea on how to code on Unity. Using a DI container in conjunction with Unity, it's possible to write code that is more extensible, reusable and less `MonoBehaviour` centric (in most cases, a regular class can do just fine or better).\r\n\r\nThis way your code can become more modular and your components less tightly coupled to each other.\r\n\r\n#### \u003ca id=\"common-use-cases\"\u003e\u003c/a\u003eCommon use cases\r\n\r\n##### Class dependency\r\n\r\nImagine you class depend on a given service that provides some action it may need:\r\n\r\n```cs\r\npublic class MyClass {\r\n\tpublic void DoAction() {\r\n\t\tvar service = new SomeService();\r\n\t\tservice.SomeAction();\r\n\t}\r\n}\r\n```\r\n\r\nIf in the future you need to change the implementation of the service, you'll have to get back to the class and change it. It can work just fine for small projects, but as the codebase grows, it can become a (error prone) nightmare to chase all these references.\r\n\r\nSo, you can change to a more decoupled code, making `MyClass` not having to worry about the specific implementation of `SomeService` it uses:\r\n\r\n```cs\r\npublic class MyClass {\r\n\tprivate IService service;\r\n\r\n\tpublic MyClass(IService service) {\r\n\t\tthis.service = service;\r\n\t}\r\n\r\n\tpublic void DoAction() {\r\n\t\tthis.service.SomeAction();\r\n\t}\r\n}\r\n```\r\n\r\nThe idea is that you invert the resolution of the dependency up into the execution flow.\r\n\r\nNow, any class that needs to use `MyClass` also has to to provide a service reference to it by constructor:\r\n\r\n```cs\r\npublic class MyOtherClass {\r\n\tprivate IService service;\r\n\r\n\tpublic MyOtherClass(IService service) {\r\n\t\tthis.service = service;\r\n\t}\r\n\r\n\tpublic void DoAction() {\r\n\t\tvar myClass = new MyClass(this.service)\r\n\t\tmyClass.DoAction();\r\n\t}\r\n}\r\n```\r\n\r\nBut you could write it even better: given `MyOtherClass` depends only on `MyClass` (`IService` is just a *tramp variable* - a variable that is there to be passed to other object), there's no need to store a reference to the `IService` object:\r\n\r\n```cs\r\npublic class MyOtherClass {\r\n\tprivate MyClass myClass;\r\n\r\n\tpublic MyOtherClass(MyClass myClass) {\r\n\t\tthis.myClass = myClass;\r\n\t}\r\n\r\n\tpublic void DoAction() {\r\n\t\tthis.myClass.DoAction();\r\n\t}\r\n}\r\n```\r\n\r\nHowever, any class that uses `MyOtherClass` must also fullfill any dependencies it needs, again up into the execution flow, until a place where all the dependencies are resolved. This place is called the [composition root](http://blog.ploeh.dk/2011/07/28/CompositionRoot/).\r\n\r\nAnd that's where a DI container come in handy. In the composition root, a DI container is created and configured to resolve and wire all dependencies of any objects used by your code so you don't have to worry about it!\r\n\r\n#### \u003ca id=\"further-readings\"\u003e\u003c/a\u003eFurther readings\r\n\r\n- [IoC container solves a problem you might not have but it's a nice problem to have](http://kozmic.net/2012/10/23/ioc-container-solves-a-problem-you-might-not-have-but-its-a-nice-problem-to-have/)\r\n- [IoC Container for Unity3D – part 1](http://www.sebaslab.com/ioc-container-for-unity3d-part-1/)\r\n- [IoC Container for Unity3D – part 2](http://www.sebaslab.com/ioc-container-for-unity3d-part-2/)\r\n- [The truth behind Inversion of Control – Part I – Dependency Injection](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-i-dependency-injection/)\r\n- [The truth behind Inversion of Control – Part II – Inversion of Control](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-ii-inversion-of-control/)\r\n- [The truth behind Inversion of Control – Part III – Entity Component Systems](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-iii-entity-component-systems/)\r\n- [The truth behind Inversion of Control – Part IV – Dependency Inversion Principle](http://www.sebaslab.com/the-truth-behind-inversion-of-control-part-iii-entity-component-systems/)\r\n- [From STUPID to SOLID Code!](http://williamdurand.fr/2013/07/30/from-stupid-to-solid-code/)\r\n\r\n### \u003ca id=\"structure\"\u003e\u003c/a\u003eStructure\r\n\r\nThe structure of *Adic* is divided into five parts:\r\n\r\n1. **InjectionContainer/Container:** binds, resolves, injects and holds dependencies. Technically, the container is a *Binder* and an *Injector* at the same time.\r\n2. **Binder:** binds a type to another type or instance with inject conditions.\r\n3. **Injector:** resolves and injects dependencies.\r\n4. **Context Root:** main context in which the containers are in. Acts as an entry point for the game. It's implemented through an \u003ca href=\"#extension-context-root\"\u003eextension\u003c/a\u003e.\r\n5. **Extensions:** provides additional features to the framework.\r\n\r\n### \u003ca id=\"types-of-bindings\"\u003e\u003c/a\u003eTypes of bindings\r\n\r\n* **Transient:** a new instance is created each time a dependency needs to be resolved.\r\n* **Singleton:** a single instance is created and used on any dependency resolution.\r\n* **Factory:** creates the instance and returns it to the container.\r\n\r\n### \u003ca id=\"namespace-conventions\"\u003e\u003c/a\u003eNamespace conventions\r\n\r\n*Adic* is organized internally into different namespaces that represents the framework components. However, the commonly used components are under `Adic` namespace:\r\n\r\n1. `Inject` attribute;\r\n2. `InjectionContainer`;\r\n3. `IFactory`;\r\n4. Extensions (like `ContextRoot` and `UnityBinding`).\r\n\r\n### \u003ca id=\"chaining\"\u003e\u003c/a\u003eChaining\r\n\r\nMethods from the container and bindings creation can be chained to achieve a more compact code:\r\n\r\n```cs\r\n//Create the container.\r\nthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t//Register any extensions the container may use.\r\n\t.RegisterExtension\u003cCommanderContainerExtension\u003e()\r\n\t.RegisterExtension\u003cEventCallerContainerExtension\u003e()\r\n\t.RegisterExtension\u003cUnityBindingContainerExtension\u003e()\r\n\t//Add bindings.\r\n    .Bind\u003cType1\u003e.To\u003cAnotherType1\u003e()\r\n    .Bind\u003cType2\u003e.To\u003cAnotherType2\u003e().As(\"Identifier\")\r\n    .Bind\u003cType3\u003e.ToGameObject(\"GameObjectName\").AsObjectName()\r\n    .Bind\u003cType4\u003e.ToSingleton\u003cAnotherType3\u003e();\r\n```\r\n\r\n**Good practice:** when chaining, always place the bindings in the end of the chain or use \u003ca href=\"#bindings-setup\"\u003ebindings setup\u003c/a\u003e to organize your bindings.\r\n\r\n## \u003ca id=\"quick-start\"\u003e\u003c/a\u003eQuick start\r\n\r\n1\\. Create the context root (e.g. GameRoot.cs) of your scene by inheriting from `Adic.ContextRoot` and attaching it to an empty game object.\r\n\r\n```cs\r\nusing UnityEngine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// Game context root.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class GameRoot : Adic.ContextRoot {\r\n\t\tpublic override void SetupContainers() {\r\n\t\t\t//Setup the containers.\r\n\t\t}\r\n\r\n\t\tpublic override void Init() {\r\n\t\t\t//Init the game.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Hint:** when using a context root for each scene of your game, to make the project more organized, create folders for each of your scenes that will hold their own scripts and context roots.\r\n\r\n2\\. In the `SetupContainers()` method, create and add any containers you may need, also configuring their bindings.\r\n\r\n```cs\r\npublic override void SetupContainers() {\r\n\t//Create a container.\r\n\tthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t\t//Setup bindinds.\r\n\t\t.Bind\u003cWhatever\u003e().ToSelf();\r\n}\r\n```\r\n\r\n**Attention:** the order in which you place the bindings is very important. If class A requires an injection of class B, class B should be bound to the container before class A.\r\n\r\n**Hint:** in *Adic*, the lifetime of your bindings is the lifetime of your containers - you can create as many containers as you want to hold your dependencies.\r\n\r\n**Good practice:** if you have many bindings to add to a container, it's better to create reusable objects that can setup related bindings together. Please see \u003ca href=\"#bindings-setup\"\u003eBindings setup\u003c/a\u003e for more information.\r\n\r\n3\\. On the `Init()` method, place any code to start your game.\r\n\r\n**Note:** the idea of this method is to work as an entry point for your game, like a `main()` method on console applications.\r\n\r\n4\\. Attach the context root created by you on an empty game object in your scene.\r\n\r\n5\\. Start dependency injecting!\r\n\r\n## \u003ca id=\"api\"\u003e\u003c/a\u003eAPI\r\n\r\n### \u003ca id=\"bindings\"\u003e\u003c/a\u003eBindings\r\n\r\nBinding is the action of linking a type to another type or instance. *Adic* makes it simple by providing different ways to create your bindings.\r\n\r\nEvery binding must occur from a certain key type by calling the `Bind()` method of the container.\r\n\r\nThe simple way to bind e.g. some interface to its class implementation is as below:\r\n\r\n```cs\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cClassImplementation\u003e();\r\n```\r\n\r\nIt's also possible to bind a class to an existing instance:\r\n\r\n```cs\r\ncontainer.Bind\u003cSomeInterface\u003e().To(someInstance);\r\n```\r\n\r\nYou can also bind a Unity component to a game object that has that particular component:\r\n\r\n```cs\r\n// By name...\r\ncontainer.Bind\u003cTransform\u003e().ToGameObject(\"GameObjectNameOnHierarchy\");\r\n// ...or by passing the actual GameObject.\r\ncontainer.Bind\u003cTransform\u003e().ToGameObject(myGameObject);\r\n```\r\n\r\nOr a loaded prefab:\r\n\r\n```cs\r\ncontainer.Bind\u003cTransform\u003e().ToPrefab(myPrefab);\r\n```\r\n\r\nAnd, if needed, non-generics versions of bindings' methods are also available:\r\n\r\n```cs\r\ncontainer.Bind(someType).To(anotherType);\r\n```\r\n\r\nThe next sections will cover all the available bindings *Adic* provides.\r\n\r\n#### To Self\r\n\r\nBinds the key type to a transient of itself. The key must be a class.\r\n\r\n```cs\r\ncontainer.Bind\u003cClassType\u003e().ToSelf();\r\n```\r\n\r\n#### To Singleton\r\n\r\nBinds the key type to a singleton of itself. The key must be a class.\r\n\r\n```cs\r\ncontainer.Bind\u003cClassType\u003e().ToSingleton();\r\n```\r\n\r\nIt's also possible to create a singleton of the key type to another type. In this case, the key may not be a class.\r\n\r\n```cs\r\n//Using generics...\r\ncontainer.Bind\u003cInterfaceType\u003e().ToSingleton\u003cClassType\u003e();\r\n//...or instance type.\r\ncontainer.Bind\u003cInterfaceType\u003e().ToSingleton(classTypeObject);\r\n```\r\n\r\n#### To another type\r\n\r\nBinds the key type to a transient of another type. In this case, the *To* type will be instantiated every time a resolution of the key type is asked.\r\n\r\n```cs\r\n//Using generics...\r\ncontainer.Bind\u003cInterfaceType\u003e().To\u003cClassType\u003e();\r\n//..or instance type.\r\ncontainer.Bind\u003cInterfaceType\u003e().To(classTypeObject);\r\n```\r\n\r\n#### To instance\r\n\r\nBinds the key type to an instance.\r\n\r\n```cs\r\n//Using generics...\r\ncontainer.Bind\u003cInterfaceType\u003e().To\u003cClassType\u003e(instanceOfClassType);\r\n//..or instance type.\r\ncontainer.Bind\u003cInterfaceType\u003e().To(classTypeObject, instanceOfClassType);\r\n```\r\n\r\n#### To all types in a namespace as transient\r\n\r\nBinds the key type to all assignable types in a given namespace as transient bindings.\r\n\r\n**Note 1:** it will create a \u003ca href=\"#multiple-injection\"\u003emultiple binding\u003c/a\u003e if there's more than one type in the namespace that is assignable to the key type.\r\n\r\n**Note 2:** currently it's not possible to use conditions when binding to all types in a namespace.\r\n\r\n```cs\r\n// Only the informed namespace.\r\ncontainer.Bind\u003cSomeType\u003e().ToNamespace(\"MyNamespace.Whatever\");\r\n\r\n// Including children namespaces.\r\ncontainer.Bind\u003cSomeType\u003e().ToNamespace(\"MyNamespace.Whatever\", true);\r\n```\r\n\r\n#### To all types in a namespace as singleton\r\n\r\nBinds the key type to all assignable types in a given namespace as singleton bindings.\r\n\r\n**Note 1:** it will create a \u003ca href=\"#multiple-injection\"\u003emultiple binding\u003c/a\u003e if there's more than one type in the namespace that is assignable to the key type.\r\n\r\n**Note 2:** currently it's not possible to use conditions when binding to all types in a namespace.\r\n\r\n```cs\r\n// Only the informed namespace.\r\ncontainer.Bind\u003cSomeType\u003e().ToNamespaceSingleton(\"MyNamespace.Whatever\");\r\n\r\n// Including children namespaces.\r\ncontainer.Bind\u003cSomeType\u003e().ToNamespaceSingleton(\"MyNamespace.Whatever\", true);\r\n```\r\n\r\n#### To a Factory\r\n\r\nBinds the key type to a factory. The factory must implement the `Adic.IFactory` interface.\r\n\r\n```cs\r\n//Binding factory by generics...\r\ncontainer.Bind\u003cInterfaceType\u003e().ToFactory\u003cFactory\u003e();\r\n//...or type instance...\r\ncontainer.Bind\u003cInterfaceType\u003e().ToFactory(typeFactory);\r\n//...or a factory instance.\r\ncontainer.Bind\u003cInterfaceType\u003e().ToFactory(factoryInstance);\r\n```\r\n\r\nSee \u003ca href=\"#factories\"\u003eFactories\u003c/a\u003e for more information.\r\n\r\n#### To game object\r\n\r\nBinds the key type to a singleton of itself or some type on a new game object.\r\n\r\n**Good practice:** to prevent references to destroyed objects, only bind to game objects that won't be destroyed in the scene.\r\n\r\n```cs\r\n//Binding to itself...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToGameObject();\r\n//...or some other component using generics...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObject\u003cSomeMonoBehaviour\u003e();\r\n//..or some other component by instance type.\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObject(someMonoBehaviourType);\r\n```\r\n\r\nThe newly created game object will have the same name as the key type.\r\n\r\n#### To game object by name\r\n\r\nBinds the key type to a singleton `UnityEngine.Component` of itself or some type on a game object of a given name.\r\n\r\n**Good practice:** to prevent references to destroyed objects, only bind to game objects that won't be destroyed in the scene.\r\n\r\nIf the component is not found on the game object, it will be added.\r\n\r\n##### By name\r\n\r\n```cs\r\n//Binding to itself by name...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToGameObject(\"GameObjectName\");\r\n//...or some other component using generics and name...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObject\u003cSomeMonoBehaviour\u003e(\"GameObjectName\");\r\n//..or some other component by instance type and name.\r\ncontainer.Bind\u003cSomeInterface\u003e()().ToGameObject(someMonoBehaviourType, \"GameObjectName\");\r\n```\r\n\r\n##### By instance\r\n\r\n```cs\r\n//Binding to itself by instance...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToGameObject(myGameObject);\r\n//...or some other component using generics and instance...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObject\u003cSomeMonoBehaviour\u003e(myGameObject);\r\n//..or some other component by instance type and instance.\r\ncontainer.Bind\u003cSomeInterface\u003e()().ToGameObject(someMonoBehaviourType, myGameObject);\r\n```\r\n\r\n#### To game object with tag\r\n\r\nBinds the key type to a singleton `UnityEngine.Component` of itself or some type on a game object of a given tag.\r\n\r\n**Good practice:** to prevent references to destroyed objects, only bind to game objects that won't be destroyed in the scene.\r\n\r\nIf the component is not found on the game object, it will be added.\r\n\r\n```cs\r\n//Binding to itself by tag...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToGameObjectWithTag(\"Tag\");\r\n//...or some other component using generics and tag...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObjectWithTag\u003cSomeMonoBehaviour\u003e(\"Tag\");\r\n//..or some other component by instance type and tag.\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObjectWithTag(someMonoBehaviourType, \"Tag\");\r\n```\r\n\r\n#### To game objects with tag\r\n\r\nBinds the key type to singletons `UnityEngine.Component` of itself or some type on a game object of a given tag.\r\n\r\n**Good practice:** to prevent references to destroyed objects, only bind to game objects that won't be destroyed in the scene.\r\n\r\nIf the component is not found on the game object, it will be added.\r\n\r\n```cs\r\n//Binding to itself by tag...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToGameObjectsWithTag(\"Tag\");\r\n//...or some other component using generics and tag...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObjectsWithTag\u003cSomeMonoBehaviour\u003e(\"Tag\");\r\n//..or some other component by instance type and tag.\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObjectsWithTag(someMonoBehaviourType, \"Tag\");\r\n```\r\n\r\n#### To prefab transient\r\n\r\nBinds the key type to a transient `UnityEngine.Component` of itself or some type on the prefab.\r\n\r\nIf the component is not found on the game object, it will be added.\r\n\r\n**Note:** every resolution of a transient prefab will generate a new instance. So, even if the component resolved from the prefab is destroyed, it won't generate any missing references in the container.\r\n\r\n```cs\r\n//Binding prefab to itself...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToPrefab(myPrefab);\r\n//...or to another component on the prefab using generics...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToPrefab\u003cSomeMonoBehaviour\u003e(myPrefab);\r\n//...or to another component on the prefab using instance tyoe.\r\ncontainer.Bind\u003cSomeInterface\u003e().ToPrefab(someMonoBehaviourType, myPrefab);\r\n```\r\n\r\n#### To prefab singleton\r\n\r\nBinds the key type to a singleton `UnityEngine.Component` of itself or some type on a newly instantiated prefab.\r\n\r\n**Good practice:** to prevent references to destroyed objects, only bind to prefabs that won't be destroyed in the scene.\r\n\r\n```cs\r\n//Binding singleton prefab to itself...\r\ncontainer.Bind\u003cSomeMonoBehaviour\u003e().ToPrefabSingleton(myPrefab);\r\n//...or to another component on the prefab using generics...\r\ncontainer.Bind\u003cSomeInterface\u003e().ToPrefabSingleton\u003cSomeMonoBehaviour\u003e(myPrefab);\r\n//...or to another component on the prefab using instance type.\r\ncontainer.Bind\u003cSomeInterface\u003e().ToPrefabSingleton(someMonoBehaviourType, myPrefab);\r\n```\r\n\r\n### \u003ca id=\"constructor-injection\"\u003e\u003c/a\u003eConstructor injection\r\n\r\n*Adic* will always try to resolve any dependencies the constructor may need by using information from its bindings or trying to instantiate any types that are unknown to the binder.\r\n\r\nThere's no need to decorate constructors' parameteres with `Inject` attributes - they will be resolved automatically. However, if you are using identified parameters, you should use the `Inject` attribute:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Class constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"param1\"\u003eIdentified parameter description.\u003c/param\u003e\r\n\t\t/// \u003cparam name=\"param2\"\u003eParameter description.\u003c/param\u003e\r\n\t\tpublic MyClass([Inject(\"Identifier\")] param1, SomeType param2) {\r\n\t\t\t...\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Note:** if there's more than one constructor, *Adic* always look for the one with less parameteres. However, \u003ca href=\"#multiple-constructors\"\u003eit's possible to indicate which constructor should be used\u003c/a\u003e on a multi constructor class.\r\n\r\n### \u003ca id=\"member-injection\"\u003e\u003c/a\u003eMember injection\r\n\r\n*Adic* can perform dependency injection on public and non public (private, protected and internal) fields and properties of classes. To make it happen, just decorate the members with the `Inject` attribute:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic SomeClass fieldToInject;\r\n\t\t/// \u003csummary\u003eField NOT to be injected.\u003c/summary\u003e\r\n\t\tpublic SomeClass fieldNotToInject;\r\n\r\n\t\t/// \u003csummary\u003eProperty to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tprivate SomeOtherClass propertyToInject { get; set; }\r\n\t\t/// \u003csummary\u003eProperty NOT to be injected.\u003c/summary\u003e\r\n\t\tprivate SomeOtherClass propertyNotToInject { get; set; }\r\n\t}\r\n}\r\n```\r\n\r\n**Attention:** injecting on reference objects will only occur if the object has no value (its value is `null`).\r\n\r\n### \u003ca id=\"method-injection\"\u003e\u003c/a\u003eMethod injection\r\n\r\nMethod injection works like constructor injection, but on methods:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Injected method, called after all the dependencies have been resolved.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"param1\"\u003eIdentified parameter description.\u003c/param\u003e\r\n\t\t/// \u003cparam name=\"param2\"\u003eParameter description.\u003c/param\u003e\r\n\t\t[Inject]\r\n\t\tpublic void MyMethod1([Inject(\"Identifier\")] SomeType param1, SomeType param2) {\r\n\t\t\t...\r\n\t\t}\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Injected method, called after all the dependencies have been resolved.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"param\"\u003eParameter description.\u003c/param\u003e\r\n\t\t[Inject]\r\n\t\tprivate void MyMethod2(SomeType param) {\r\n\t\t\t...\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nMethod injection occurs after all injections on the class. So, it's possible to use it as a post constructor:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tprivate SomeClass fieldToInject;\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Class constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tpublic MyClass() {\r\n\t\t\t...\r\n\t\t}\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Injected method acting as a post constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tprivate void PostConstructor() {\r\n\t\t\t...\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Good practice:** injected methods can be used as constructors on `MonoBehaviour` components.\r\n\r\n**Good practice:** injected methods can be used to perform initilizations or configurations on objects.\r\n\r\n**Good practice:** always use non-generic injected methods to prevent [`JIT compile method`](http://docs.unity3d.com/Manual/TroubleShootingIPhone.html) exceptions on [AOT platforms](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) (like iOS and WebGL).\r\n\r\n### \u003ca id=\"multiple-constructors\"\u003e\u003c/a\u003eMultiple constructors\r\n\r\nIn case you have multiple constructors, it's possible to indicate to *Adic* which one should be used by decorating it with the `Inject` attribute:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Class constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tpublic MyClass() {\r\n\t\t\t...\r\n\t\t}\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Class constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameterName\"\u003eParameter description\u003c/param\u003e\r\n\t\t[Inject]\r\n\t\tpublic MyClass(Type parameterName) {\r\n\t\t\t...\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n### \u003ca id=\"multiple-injection\"\u003e\u003c/a\u003eMultiple injection\r\n\r\nIt's possible to inject multiple objects of the same type by creating a series of bindings of the same key type. In this case, the injection occurs on an array of the key type.\r\n\r\nBinding multiple objects to the same key:\r\n\r\n```cs\r\ncontainer\r\n\t.Bind\u003cGameObject\u003e().ToGameObject(\"Enemy1\")\r\n\t.Bind\u003cGameObject\u003e().ToGameObject(\"Enemy2\")\r\n\t.Bind\u003cGameObject\u003e().ToGameObject(\"Enemy3\")\r\n\t.Bind\u003cGameObject\u003e().ToGameObject(\"Enemy4\")\r\n\t.Bind\u003cGameObject\u003e().ToGameObject(\"Enemy5\");\r\n```\r\n\r\nMultiple injection in a field:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003eEnemies on the game.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic GameObject[] enemies;\r\n\t}\r\n}\r\n```\r\n\r\nIt's possible to manually resolve multiple objects. Please see \u003ca href=\"#manual-type-resolution\"\u003eManual type resolution\u003c/a\u003e for more information.\r\n\r\n### \u003ca id=\"behaviour-injection\"\u003e\u003c/a\u003eBehaviour injection\r\n\r\nIt's possible to perform injection on custom `MonoBehaviour` and `StateMachineBehaviour` scripts through the extensions \u003ca href=\"#extension-mono-injection\"\u003eMono Injection\u003c/a\u003e and \u003ca href=\"#extension-state-injection\"\u003eState Injection\u003c/a\u003e, which are enabled by default.\r\n\r\n#### \u003ca id=\"monobehaviour-injection\"\u003e\u003c/a\u003eMonoBehaviour injection\r\n\r\nTo perform injection on custom `MonoBehaviour` fields and properties, simply call the `Inject()` extension method of the `MonoBehaviour`:\r\n\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My MonoBehaviour summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyBehaviour : MonoBehaviour {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic SomeClass fieldToInject;\r\n\r\n\t\tprotected void Start() {\r\n\t\t\tthis.Inject();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### \u003ca id=\"base-monobehaviour\"\u003e\u003c/a\u003eBase MonoBehaviour\r\n\r\nTo make injection even simpler, create a base behaviour from which all your `MonoBehaviour` can inherit, calling the `Inject()` method during `Start()`:\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// Base MonoBehaviour.\r\n\t/// \u003c/summary\u003e\r\n\tpublic abstract class BaseBehaviour : MonoBehaviour {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Called when the component is starting.\r\n\t\t///\r\n\t\t/// If overriden on derived classes, always call base.Start().\r\n\t\t/// \u003c/summary\u003e\r\n\t\tprotected virtual void Start() {\r\n\t\t\tthis.Inject();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n#### \u003ca id=\"statemachinebehaviour-injection\"\u003e\u003c/a\u003eStateMachineBehaviour injection\r\n\r\nTo perform injection on custom `StateMachineBehaviour` fields and properties, simply call the `Inject()` extension method on any of the state events:\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My StateMachineBehaviour summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyStateMachineBehaviour : StateMachineBehaviour {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic SomeClass fieldToInject;\r\n\r\n\t\tpublic override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {\r\n\t\t\tthis.Inject();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Note:** only available on Unity 5+.\r\n\r\n##### \u003ca id=\"base-statemachinebehaviour\"\u003e\u003c/a\u003eBase StateMachineBehaviour\r\n\r\nTo make injection even simpler, create a base behaviour from which all your `StateMachineBehaviour` can inherit:\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// Base StateMachineBehaviour.\r\n\t/// \u003c/summary\u003e\r\n\tpublic abstract class BaseStateBehaviour : StateMachineBehaviour {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Behaviour constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tpublic BaseStateBehaviour() {\r\n\t\t\tthis.Inject();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n#### \u003ca id=\"scene-injection\"\u003e\u003c/a\u003eScene injection\r\n\r\nOn some performance sensitive games it's important to ensure that every injection occurs before the game starts, in a scene level. *Adic* provides three ways to perform a scene wide injection, which are configured by selecting the appropriate injection type on the \u003ca href=\"#extension-context-root\"\u003eContext Root\u003c/a\u003e inspector.\r\n\r\n**Note:** there's no better or worse strategy. It only depends on the game you are working on and developer preferences, given all strategies can achieve the same performance goals if all objects used during the game are created before the game starts. Read the \u003ca href=\"#performance\"\u003ePerformance\u003c/a\u003e section for more performance considerations.\r\n\r\n##### Manual\r\n\r\nThe injection is performed manually, without a scene wide automatic injection. This is the default setting.\r\n\r\nIt's recommended to use a \u003ca id=\"base-monobehaviour\"\u003ebase MonoBehaviour\u003c/a\u003e to perform injections.\r\n\r\n##### Children\r\n\r\nThe injection is performed on all `MonoBehaviour` or any `MonoBehaviour` derived type (e.g. a \u003ca id=\"base-monobehaviour\"\u003ebase `MonoBehaviour`\u003c/a\u003e) that are children of the context root.\r\n\r\n##### Base type\r\n\r\nThe injection is performed on all `MonoBehaviour` or any `MonoBehaviour` derived type (e.g. a \u003ca id=\"base-monobehaviour\"\u003ebase `MonoBehaviour`\u003c/a\u003e) throughout the scene.\r\n\r\n#### \u003ca id=\"injecting-multiple-containers\"\u003e\u003c/a\u003eInjecting from multiple containers\r\n\r\nWhen injecting into `MonoBehaviour`/`StateMachineBehaviour` using the `this.Inject()` method, every available container in the \u003ca href=\"#quick-start\"\u003econtext root\u003c/a\u003e is used. If you want to restrict the containers from which injection occurs, use the `InjectFromContainer` attribute in conjunction with a container identifier.\r\n\r\n##### Setting a container identifier\r\n\r\nWhen creating the container, set an identifier through its constructor:\r\n\r\n```cs\r\n//Create the container with an identifier.\r\nthis.AddContainer(new InjectionContainer(\"identifier\"))\r\n\t//Register any extensions the container may use.\r\n\t.RegisterExtension\u003cUnityBindingContainerExtension\u003e();\r\n```\r\n\r\n**Good practice:** identifiers can be any object. However, it's recommended to use only strings and enums.\r\n\r\n##### Adding the attribute\r\n\r\nIn the `MonoBehaviour`/`StateMachineBehaviour` that should receive injection only from a certain container, add the `InjectFromContainer` attribute with the container's identifier:\r\n\r\n##### MonoBehaviour\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My MonoBehaviour summary.\r\n\t/// \u003c/summary\u003e\r\n\t[InjectFromContainer(\"identifier\")]\r\n\tpublic class MyBehaviour : MonoBehaviour {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic SomeClass fieldToInject;\r\n\r\n\t\tprotected void Start() {\r\n\t\t\tthis.Inject();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### StateMachineBehaviour\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My StateMachineBehaviour summary.\r\n\t/// \u003c/summary\u003e\r\n\t[InjectFromContainer(\"identifier\")]\r\n\tpublic class MyStateMachineBehaviour : StateMachineBehaviour {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic SomeClass fieldToInject;\r\n\r\n\t\tpublic override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {\r\n\t\t\tthis.Inject();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n### \u003ca id=\"conditions\"\u003e\u003c/a\u003eConditions\r\n\r\nConditions allow a more customized approach when injecting dependencies into constructors and fields/properties.\r\n\r\nUsing conditions you can:\r\n\r\n1\\. Identify a binding with an identifier, so you can indicate it as a parameter in the `Inject` attribute on constructors and fields/properties:\r\n\r\nWhen binding:\r\n\r\n```cs\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cSomeClass\u003e().As(\"Identifier\");\r\n```\r\n\r\nWhen binding to Unity Objects, it's possible to use the object name automatically as the binding:\r\n\r\n```cs\r\ncontainer.Bind\u003cSomeInterface\u003e().ToGameObject(\"GameObjectName\").AsObjectName();\r\n```\r\n\r\nWhen injecting into constructor parameters:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Class constructor.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameter\"\u003eParameter to be injected.\u003c/param\u003e\r\n\t\tpublic MyClass([Inject(\"Identifier\")] SomeInterface parameter) {\r\n\t\t\t//Code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nWhen injecting into fields/properties:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass {\r\n\t\t/// \u003csummary\u003eField to be injected.\u003c/summary\u003e\r\n\t\t[Inject(\"Identifier\")]\r\n\t\tpublic SomeInterface field;\r\n\r\n\t\t/// \u003csummary\u003eProperty to be injected.\u003c/summary\u003e\r\n\t\t[Inject(\"Identifier\")]\r\n\t\tpublic SomeInterface property { get; set; }\r\n\t}\r\n}\r\n```\r\n\r\n**Good practice:** identifiers can be any object. However, it's recommended to use only strings and enums.\r\n\r\n2\\. Indicate in which objects a binding can be injected, by type or instance:\r\n\r\n```cs\r\n//Using generics...\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cSomeClass\u003e().WhenInto\u003cMyClass\u003e();\r\n//...or type instance...\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cSomeClass\u003e().WhenInto(myClassInstanceType);\r\n//...or by a given instance.\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cSomeClass\u003e().WhenIntoInstance(myClassInstanceType);\r\n```\r\n\r\n3\\. Create complex conditions by using an anonymous method:\r\n\r\n```cs\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cSomeClass\u003e().When(context =\u003e\r\n\t\tcontext.member.Equals(InjectionMember.Field) \u0026\u0026\r\n        context.parentType.Equals(typeof(MyClass))\r\n\t);\r\n```\r\n\r\nThe context provides the following fields:\r\n\r\n1. **member** (`Adic.InjectionMember` enum): the class member in which the injection is occuring (*None*, *Constructor*, *Field* or *Property*).\r\n2. **memberType** (`System.Type`): the type of the member in which the injection is occuring.\r\n3. **memberName** (`string`): the name of the member in which the injection is occuring.\r\n4. **identifier** (`object`): the identifier of the member in which the injection is occuring (from `Inject` attribute).\r\n5. **parentType** (`System.Type`): the type of the object in which the injection is occuring.\r\n6. **parentInstance** (`object`): the instance of the object in which the injection is occuring.\r\n7. **injectType** (`System.Type`): the type of the object being injected.\r\n\r\n### \u003ca id=\"tags\"\u003e\u003c/a\u003eTags\r\n\r\nTags can be used to easily unbind bindings.\r\n\r\n1\\. Tag a binding with as many tags as required:\r\n\r\n```cs\r\ncontainer.Bind\u003cSomeInterface\u003e().To\u003cSomeClass\u003e().As(\"Identifier\").Tag(\"Tag1\", \"Tag2\", \"Tag3\");\r\n```\r\n\r\n2\\. Unbind all bindings with a given tag:\r\n\r\n```cs\r\ncontainer.UnbindByTag(\"Tag1\");\r\n```\r\n\r\n### \u003ca id=\"update\"\u003e\u003c/a\u003eUpdate\r\n\r\nIt's possible to have an `Update()` method on regular classes (that don't inherit from `MonoBehaviour`) by implementing the `Adic.IUpdatable` interface.\r\n\r\nSee \u003ca href=\"#extension-event-caller\"\u003eEvent Caller\u003c/a\u003e for more information.\r\n\r\n### \u003ca id=\"dispose\"\u003e\u003c/a\u003eDispose\r\n\r\nWhen a scene is destroyed, it's possible to have a method that can be called to e.g. free up resources. To do it, implement the `System.IDisposable` interface on any class that you want to have this option.\r\n\r\nSee \u003ca href=\"#extension-event-caller\"\u003eEvent Caller\u003c/a\u003e for more information.\r\n\r\n### \u003ca id=\"instance-resolution-modes\"\u003e\u003c/a\u003eInstance resolution modes\r\n\r\n*Adic* provides two instance resolution modes:\r\n\r\n1. **ALWAYS_RESOLVE** (default): always try to resolve every type that requires injection, even ones that are not bound to the container.\r\n2. **RETURN_NULL**: only resolves types that are bound to the container. Trying to resolve a non-bound type will return a null reference.\r\n\r\n#### Setting a resolution mode\r\n\r\nInstance resolution modes can be configured through the `Adic.InjectionContainer` constructor or by changing the `resolutionMode` property:\r\n\r\n```cs\r\n//Setting a resolution mode through constructor...\r\nvar container = new InjectionContainer(ResolutionMode.RETURN_NULL);\r\n//...and changing it through property.\r\ncontainer.resolutionMode = ResolutionMode.ALWAYS_RESOLVE;\r\n```\r\n\r\n### \u003ca id=\"manual-type-resolution\"\u003e\u003c/a\u003eManual type resolution\r\n\r\nIf you need to get a type from the container but do not want to use injection through constructor or fields/properties, it's possible to execute a manual resolution directly by calling the `Resolve()` method:\r\n\r\n```cs\r\n//Resolving using generics...\r\nvar instance = container.Resolve\u003cType\u003e();\r\n//...or using generics for objects with a given identifier...\r\nvar instance = container.Resolve\u003cType\u003e(\"Identifier\");\r\n//...or by type instance...\r\ninstance = container.Resolve(typeInstance);\r\n//...or by objects with a given identifier...\r\ninstance = container.Resolve(\"Identifier\");\r\n//...or by type instance for objects with a given identifier.\r\ninstance = container.Resolve(typeInstance, \"Identifier\");\r\n```\r\n\r\nIt's also possible to resolve all objects of a given type:\r\n\r\n```cs\r\n//Resolving all objects using generics...\r\nvar instances = container.ResolveAll\u003cType\u003e();\r\n//...or using generics for objects with a given identifier...\r\nvar instance = container.ResolveAll\u003cType\u003e(\"Identifier\");\r\n//...or by type instance...\r\ninstances = container.ResolveAll(typeInstance);\r\n//...or by objects with a given identifier...\r\ninstance = container.ResolveAll(\"Identifier\");\r\n//...or by type instance for objects with a given identifier.\r\ninstance = container.ResolveAll(typeInstance, \"Identifier\");\r\n```\r\n\r\n**Note:** although it's possible to resolve instances by identifier, currently manual resolution of bindings that have other conditions is not supported.\r\n\r\n### \u003ca id=\"factories\"\u003e\u003c/a\u003eFactories\r\n\r\nWhen you need to handle the instantiation of an object manually, it's possible to create a factory class by inheriting from `Adic.IFactory`:\r\n\r\n```cs\r\nusing Adic.Injection;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My factory.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyFactory : Adic.IFactory {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Creates an instance of the object of the type created by the factory.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"context\"\u003eInjection context.\u003c/param\u003e\r\n\t\t/// \u003creturns\u003eThe instance.\u003c/returns\u003e\r\n\t\tpublic object Create(InjectionContext context) {\r\n\t\t\t//Instantiate and return the object.\r\n\t\t\tvar myObject = new MyObject();\r\n\t\t\treturn myObject;\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nThe `InjectionContext` object contains information about the current injection/resolution, which can be used to help deciding how the instance will be created by the factory.\r\n\r\nTo bind a type to a factory class, use the `ToFactory()`:\r\n\r\n```cs\r\n//Binding factory by generics...\r\ncontainer.Bind\u003cSomeType\u003e().ToFactory\u003cMyFactory\u003e();\r\n//...or type instance...\r\ncontainer.Bind\u003cSomeType\u003e().ToFactory(typeMyFactory);\r\n//...or a factory instance.\r\ncontainer.Bind\u003cSomeType\u003e().ToFactory(factoryInstance);\r\n```\r\n\r\n**Note:** factories are resolved and injected by the container. So, it's possible to receive dependencies either by construtor and/or fields/properties.\r\n\r\n### \u003ca id=\"bindings-setup\"\u003e\u003c/a\u003eBindings setup\r\n\r\nSometimes the bindings list can become (very) large and bloat the `SetupContainers()` method of the context root. For better organization, it's possible to create reusable objects which will group and setup related bindings in a given container.\r\n\r\nTo create a bindings setup object, implement the `Adic.IBindingsSetup` interface:\r\n\r\n```cs\r\nusing Adic;\r\nusing Adic.Container;\r\n\r\nnamespace MyNamespace.Bindings {\r\n\t/// \u003csummary\u003e\r\n\t/// My bindings.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyBindings : IBindingsSetup {\r\n\t\tpublic void SetupBindings (IInjectionContainer container) {\r\n\t\t\tcontainer.Bind\u003cSomeType\u003e().ToSingleton\u003cAnotherType\u003e();\r\n\t\t\t//...more related bindings.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nTo perform a bindings setup, call the `SetupBindings()` method in the container, passing either the binding setup object as a parameter or the namespace in which the setups reside:\r\n\r\n```cs\r\n//Setup by generics...\r\ncontainer.SetupBindings\u003cMyBindings\u003e();\r\n//...or by type...\r\ncontainer.SetupBindings(typeof(MyBindings));\r\n//...or from an instance...\r\nvar bindings = MyBindings();\r\ncontainer.SetupBindings(bindings);\r\n//...or using a namespace.\r\ncontainer.SetupBindings(\"MyNamespace.Bindings\");\r\n```\r\n\r\n**Note:** the default behaviour of `SetupBindings()` with namespace is to use all `IBindingsSetup` objects under the given namespace and all its children namespaces. If you need that only `IBindingsSetup` objects in the given namespace are used, call the overload that allows indication of children namespace evaluation:\r\n\r\n```cs\r\ncontainer.SetupBindings(\"MyNamespace.Bindings\", false);\r\n```\r\n\r\n#### Binding setup priorities\r\n\r\nThe order of bindings setups matters. In case an `IBindingsSetup` object relies on bindings from another `IBindingsSetup` object, add the other setup first.\r\n\r\nHowever, if you are using `SetupBindings()` with a namespace, it's not possible to manually order the `IBindingsSetup` objects. In this case, you have to decorate the `IBindingsSetup` classes with a `BindingPriority` attribute to define the priority in which each bindings setup will be executed:\r\n\r\n```cs\r\nusing Adic;\r\nusing Adic.Container;\r\n\r\nnamespace MyNamespace.Bindings {\r\n\t/// \u003csummary\u003e\r\n\t/// My bindings.\r\n\t/// \u003c/summary\u003e\r\n\t[BindingPriority(1)]\r\n\tpublic class MyBindings : IBindingsSetup {\r\n\t\tpublic void SetupBindings (IInjectionContainer container) {\r\n\t\t\tcontainer.Bind\u003cSomeType\u003e().ToSingleton\u003cAnotherType\u003e();\r\n\t\t\t//...more related bindings.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nHigher values indicate higher priorities. If no priority value is provided, the default value of `1` will be used.\r\n\r\n### \u003ca id=\"using-commands\"\u003e\u003c/a\u003eUsing commands\r\n\r\n#### What are commands?\r\n\r\nCommands are actions executed by your game, usually in response to an event.\r\n\r\nThe concept of commands on *Adic* is to place everything the action/event needs in a single place, so it's easy to understand and maintain it.\r\n\r\nSuppose you have an event of enemy destroyed. When that occurs, you have to update UI, dispose the enemy, spawn some particles and save statistics somewhere. One approach would be dispatch the event to every object that has to do something about it, which is fine given it keeps single responsibility by allowing every object to take care of their part on the event. However, when your project grows, it can be a nightmare to find every place a given event is handled. That's when commands come in handy: you place all the code and dependencies for a certain action/event in a single place.\r\n\r\n#### Creatings commands\r\n\r\nTo create a command, inherit from `Adic.Command` and override the `Execute()` method, where you will place all the code needed to execute the command. If you have any dependencies to be injected before executing the command, add them as fields or properties and decorate them with an `Inject` attribute:\r\n\r\n```cs\r\nnamespace MyNamespace.Commands {\r\n\t/// \u003csummary\u003e\r\n\t/// My command.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyCommand : Adic.Command {\r\n\t\t/// \u003csummary\u003eSome dependency to be injected.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic object someDependency;\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Executes the command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameters\"\u003eCommand parameters.\u003c/param\u003e\r\n\t\tpublic override void Execute(params object[] parameters) {\r\n\t\t\t//Execution code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n**Hint:** it's also possible to wire any dependencies through constructor. However, in this case the dependencies will only be resolved once, during instantiation.\r\n\r\n**Good practice:** place all your commands under the same namespace, so it's easy to register them.\r\n\r\n##### Types of commands\r\n\r\n###### Pooled\r\n\r\nThe command is kept in a pool for reuse, avoiding new instantiations. It's useful for commands that need to maintain state when executing. This is the default behaviour.\r\n\r\nWhen creating pooled commands, it's possible to set the initial and maximum size of the pool for a particular command by setting, respectively, the `preloadPoolSize` and `maxPoolSize` properties:\r\n\r\n```cs\r\nnamespace MyNamespace.Commands {\r\n\t/// \u003csummary\u003e\r\n\t/// My command.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyCommand : Adic.Command {\r\n\t\t/// \u003csummary\u003eThe quantity of the command to preload on pool (default: 1).\u003c/summary\u003e\r\n\t\tpublic override int preloadPoolSize { get { return 5; } }\r\n\t\t/// \u003csummary\u003eThe maximum size pool for this command (default: 10).\u003c/summary\u003e\r\n\t\tpublic override int maxPoolSize { get { return 20; } }\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Executes the command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameters\"\u003eCommand parameters.\u003c/param\u003e\r\n\t\tpublic override void Execute(params object[] parameters) {\r\n\t\t\t//Execution code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n###### Singleton\r\n\r\nThere's only one copy of the command available, which is used every time the command is dispatched. It's useful for commands that don't need state or every dependency the command needs is given during execution. To make a command singleton, return `true` in the `singleton` property of the command:\r\n\r\n```cs\r\nnamespace MyNamespace.Commands {\r\n\t/// \u003csummary\u003e\r\n\t/// My command.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyCommand : Adic.Command {\r\n\t\t/// \u003csummary\u003eIndicates whether this command is a singleton (there's only one instance of it).\u003c/summary\u003e\r\n\t\tpublic override bool singleton { get { return true; } }\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Executes the command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameters\"\u003eCommand parameters.\u003c/param\u003e\r\n\t\tpublic override void Execute(params object[] parameters) {\r\n\t\t\t//Execution code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Note 1:** this is the default command type.\r\n\r\n**Note 2:** when using singleton commands, injection is done only through constructors or injection after command instantiation.\r\n\r\n#### Registering commands\r\n\r\nTo register a command, call the `Register()` method on the container, usually in the context root:\r\n\r\n```cs\r\nusing UnityEngine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// Game context root.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class GameRoot : Adic.ContextRoot {\r\n\t\tpublic override void SetupContainers() {\r\n\t\t\t//Create the container.\r\n\t\t\tthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t\t\t\t//Register any extensions the container may use.\r\n\t\t\t\t.RegisterExtension\u003cCommanderContainerExtension\u003e()\r\n\t\t\t\t//Registering by generics...\r\n\t\t\t\t.RegisterCommand\u003cMyCommand\u003e()\r\n\t\t\t\t//...or by type.\r\n\t\t\t\t.RegisterCommand(typeof(MyCommand));\r\n\r\n\t\t}\r\n\r\n\t\tpublic override void Init() {\r\n\t\t\t//Init the game.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Note:** when registering a command, it's placed in the container, so it's easier to resolve it and its dependencies.\r\n\r\nIt's also possible to register all commands under the same namespace by calling the `RegisterCommands()` method in the container and passing the full name of the namespace:\r\n\r\n```cs\r\npublic override void SetupContainers() {\r\n\t//Create the container.\r\n\tthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t\t//Register any extensions the container may use.\r\n\t\t.RegisterExtension\u003cCommanderContainerExtension\u003e()\r\n\t\t//Register all commands under the namespace \"MyNamespace.Commands\".\r\n\t\t.RegisterCommands(\"MyNamespace.Commands\");\r\n}\r\n```\r\n\r\n**Note:** the default behaviour of `RegisterCommands()` is to register all commands under the given namespace and all its children namespaces. If you need that only commands in the given namespace are registered, call the overload that allows indication of children namespace evaluation:\r\n\r\n```cs\r\ncontainer.RegisterCommands(\"MyNamespace.Commands\", false);\r\n```\r\n\r\n#### Dispatching commands\r\n\r\n##### From code using Command Dispatcher\r\n\r\nTo dispatch a command, just call the `Dispatch()` method on `Adic.ICommandDispatcher`, using either the generics or the by `System.Type` versions:\r\n\r\n```cs\r\n/// \u003csummary\u003e\r\n/// My method that dispatches a command.\r\n/// \u003c/summary\u003e\r\npublic void MyMethodThatDispatchesCommands() {\r\n\tdispatcher\r\n\t\t//Dispatching by generics...\r\n\t\t.Dispatch\u003cMyCommand\u003e();\r\n\t\t//...or by type...\r\n\t\t.Dispatch(typeof(MyCommand));\r\n\t\t//...and it's also possible to tag commands to make it easier to release them later.\r\n\t\t.Dispatch\u003cMyCommand\u003e().Tag(\"MyTag\");\r\n}\r\n```\r\n\r\n**Note:** tags are only added to singleton or alive commands. When tagging singleton commands, any previous tags will be replaced.\r\n\r\nIt's also possible to dispatch a command after a given period of time by calling the `InvokeDispatch()` method:\r\n\r\n```cs\r\n//Timed dispatching by generics...\r\ndispatcher.InvokeDispatch\u003cMyCommand\u003e(1.0f);\r\n//...or by type.\r\ndispatcher.InvokeDispatch(typeof(MyCommand), 1.0f);\r\n```\r\n\r\nTo use `Adic.ICommandDispatcher`, you have to inject it wherever you need to use it:\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My class that dispatches commands.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClassThatDispatchesCommands {\r\n\t\t/// \u003csummary\u003eThe command dispatcher.\u003c/summary\u003e\r\n\t\t[Inject]\r\n\t\tpublic ICommandDispatcher dispatcher;\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// My method that dispatches a command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tpublic void MyMethodThatDispatchesCommands() {\r\n\t\t\tthis.dispatcher.Dispatch\u003cMyCommand\u003e();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Hint:** commands already have a reference to its dispatcher (`this.dispatcher`).\r\n\r\n**Note 1:** when dispatching a command, it's placed in a list in the command dispatcher object, which is the one responsible for pooling and managing existing commands.\r\n\r\n**Note 2:** commands in the pool that are not singleton are *reinjected* every time they are executed.\r\n\r\n##### From code using CommandReference type\r\n\r\nThe `Adic.CommandReference` type allows the creation of properties on `MonoBehaviour` that represents a command that can be manually dispatched from code.\r\n\r\n```cs\r\nusing Unity.Engine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My MonoBehaviour summary.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyBehaviour : MonoBehaviour {\r\n\t\t/// \u003csummary\u003eReference to the command. Can be edited on Inspector.\u003c/summary\u003e\r\n\t\tpublic CommandReference someCommand;\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Manually dispatches the command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tprotected void DispatchCommand() {\r\n\t\t\tthis.someCommand.DispatchCommand();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### From game objects\r\n\r\nIt's possible to dispatch commands directly from game objects without the need to write any code using the components available in the \u003ca href=\"#extension-commander\"\u003eCommander extension\u003c/a\u003e.\r\n\r\nTo use them, just add the desired component to a game object.\r\n\r\n###### Command Dispatch\r\n\r\nProvides a routine to call a given command. The routine name is `DispatchCommand()`.\r\n\r\nUsing this component, you can e.g. call the `DispatchCommand()` method from a button in the UI or in your code.\r\n\r\nIt can be found at the `Component/Adic/Commander/Command dispatch` menu.\r\n\r\n###### Timed Command Dispatch\r\n\r\nDispatches a command based on a timer.\r\n\r\nThis component also provides the `DispatchCommand()` routine, in case you want to call it before the timer ends.\r\n\r\nIt can be found at the `Component/Adic/Commander/Timed command dispatch` menu.\r\n\r\n#### Retaining commands\r\n\r\nWhen a command needs to continue its execution beyond the `Execute()` method, it has to be retained. This way the command dispatcher knows the command should only be pooled/disposed when it finishes its execution.\r\n\r\nThis is useful not only for commands that implement `Adic.IUpdatable`, but also for commands that have to wait until certain actions (e.g. some network call) are completed.\r\n\r\nTo retain a command, just call the `Retain()` method during main execution:\r\n\r\n```cs\r\n/// \u003csummary\u003e\r\n/// Executes the command.\r\n/// \u003c/summary\u003e\r\n/// \u003cparam name=\"parameters\"\u003eCommand parameters.\u003c/param\u003e\r\npublic override void Execute(params object[] parameters) {\r\n\t//Execution code.\r\n\r\n\t//Retains the command until some long action is completed.\r\n\tthis.Retain();\r\n}\r\n```\r\n\r\nIf a command is retained, it has to be released. The command dispatcher will automatically releases commands during the destruction of scenes. However, in some situations you may want to release it manually (e.g. after some network call is completed).\r\n\r\nTo release a command, just call the `Release()` method when the execution is finished:\r\n\r\n```cs\r\n/// \u003csummary\u003e\r\n/// Called when some action is finished.\r\n/// \u003c/summary\u003e\r\npublic void OnSomeActionFinished() {\r\n\t//Releases the command.\r\n\tthis.Release();\r\n}\r\n```\r\n\r\nIt's also possible to manually release all commands of a specified type or tag by calling the `ReleaseAll()` method of the `CommandDispatcher`:\r\n\r\n```cs\r\ndispatcher\r\n\t//Releasing all commands of a given type by generics...\r\n\t.ReleaseAll\u003cSomeCommand\u003e();\r\n\t//...or by type instance...\r\n\t.ReleaseAll(typeof(SomeCommand));\r\n\t//...or by tag.\r\n\t.ReleaseAll(\"MyTag\");\r\n```\r\n\r\n#### Timed invoke\r\n\r\nIt's possible to use timed method invocation inside a command by calling the `Invoke()` method:\r\n\r\n```cs\r\nnamespace MyNamespace.Commands {\r\n\t/// \u003csummary\u003e\r\n\t/// My command.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyCommand : Adic.Command {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Executes the command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameters\"\u003eCommand parameters.\u003c/param\u003e\r\n\t\tpublic override void Execute(params object[] parameters) {\r\n\t\t\t//Invokes the \"MyMethodToInvoke\" method after 1 second.\r\n\t\t\tthis.Invoke(this.MyMethodToInvoke, 1.0f);\r\n\r\n\t\t\t//Retains the command until the invocation is finished.\r\n\t\t\tthis.Retain();\r\n\t\t}\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// My method to invoke.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tprivate void MyMethodToInvoke() {\r\n\t\t\t//Method code.\r\n\r\n\t\t\t//Releases the command after the invocation.\r\n\t\t\tthis.Release();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n**Note 1:** when an invocation is scheduled, the command is automatically retained. So, when the invocation method is called, always release the command.\r\n\r\n**Note 2:** when a command is released, all invocations are discarded.\r\n\r\n#### Coroutines\r\n\r\nIt's possible to use [coroutines](http://docs.unity3d.com/Manual/Coroutines.html) inside a command by calling the `StartCoroutine()` method:\r\n\r\n```cs\r\nnamespace MyNamespace.Commands {\r\n\t/// \u003csummary\u003e\r\n\t/// My command.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyCommand : Adic.Command {\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// Executes the command.\r\n\t\t/// \u003c/summary\u003e\r\n\t\t/// \u003cparam name=\"parameters\"\u003eCommand parameters.\u003c/param\u003e\r\n\t\tpublic override void Execute(params object[] parameters) {\r\n\t\t\t//Starts the coroutine.\r\n\t\t\tthis.StartCoroutine(this.MyCoroutine());\r\n\r\n\t\t\t//Retains the command until the coroutine is finished.\r\n\t\t\tthis.Retain();\r\n\t\t}\r\n\r\n\t\t/// \u003csummary\u003e\r\n\t\t/// My coroutine.\r\n\t\t/// \u003c/summary\u003e\r\n\t\tprivate IEnumerator MyCoroutine() {\r\n\t\t\t//Coroutine code.\r\n\r\n\t\t\t//Releases the command after execution.\r\n\t\t\tthis.Release();\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nIf needed, it's also possible to stop a coroutine after it's started by calling the `StopCoroutine()` method.\r\n\r\n**Note 1:** when a coroutine is started, the command is automatically retained. So, when the coroutine completes its execution, always release the command.\r\n\r\n**Note 2:** when a command is released, all coroutines started from that command are stopped.\r\n\r\n#### A note about scene destruction and commands\r\n\r\nWhen a scene is destroyed, all commands will be released and all registrations will be disposed.\r\n\r\nSo, if you're using a \u003ca href=\"#static-containers\"\u003econtainer that will live through scenes\u003c/a\u003e, be aware that all commands will have to be registered again.\r\n\r\n## \u003ca id=\"multiple-scenes\"\u003e\u003c/a\u003eMultiple scenes\r\n\r\nThere are different strategies when working with *Adic* in a multiple scene architecture, each one offering its own advantages.\r\n\r\nAll strategies are related to how the \u003ca href=\"#quick-start\"\u003econtext root\u003c/a\u003e and the lifetime of the container(s) are used.\r\n\r\n### Single context root for all scenes\r\n\r\nThe game uses a single context root for all scenes. In this strategy, all bindings are recreated each time a scene is loaded.\r\n\r\nIt's useful for games that use a single scene or when the recreation of the bindings is not an issue. This is the default strategy, as seem on \u003ca href=\"#quick-start\"\u003eQuick start\u003c/a\u003e.\r\n\r\n### One context root per scene\r\n\r\nThe game has one context root per scene, each one with its own container(s). In this case, it's important to use \u003ca href=\"#bindings-setup\"\u003ebindings setup\u003c/a\u003e to share bindings among all containers and a \u003ca href=\"#performance\"\u003esingle reflection cache\u003c/a\u003e to improve performance and memory consumption.\r\n\r\nIt's useful for games that have different bindings per scene.\r\n\r\n### Shared container\r\n\r\nA single container is shared among all scenes. In this strategy, it's common to have a single context root that is executed only on the first scene.\r\n\r\nTo use a shared container, when adding containers using `AddContainer()`, keep them alive between scenes by setting the `destroyOnLoad` to `false`.\r\n\r\nIt's useful for games that will always use the same bindings across all scenes.\r\n\r\n**Note:** when using a shared container, it's recommended to only bind singleton instances of objects that should live up through all scenes (e.g. a common service) to prevent missing references - when a scene is destroyed, eventually some singleton objects that are bound to the container may not exist in the new scene anymore. Also, factories that rely on state to create their objects could also be affected by missing references.\r\n\r\n### Additive scenes\r\n\r\nA single context root is executed in the first scene and all other scenes are loaded additively.\r\n\r\nTo load a scene additively, please consult [Application.LoadLevelAdditiveAsync](http://docs.unity3d.com/ScriptReference/Application.LoadLevelAdditiveAsync.html) on the Unity Documentation.\r\n\r\nIt's useful for games that use different scenes for each part of the level but share the same bindings across all of those scenes.\r\n\r\n#### A combination of all of the above\r\n\r\nEach game has its own characteristics, and eventually the same game could feature more than one multiple scene strategy. It's important to test which one would suit the needs of the project and use different strategies when required.\r\n\r\n## \u003ca id=\"order-of-events\"\u003e\u003c/a\u003eOrder of events\r\n\r\n1. Unity Awake()\r\n2. ContextRoot calls SetupContainers()\r\n3. ContextRoot calls Init() on all containers\r\n4. Each container generates cache for its types\r\n5. Each container initializes their extensions\r\n6. ContextRoot calls Init()\r\n7. Unity Start() on all `MonoBehaviour`\r\n8. Injection on `MonoBehaviour`\r\n9. Update() is called on every object that implements `Adic.IUpdatable`\r\n10. Scene is destroyed\r\n11. Dispose() is called on every object that implements `System.IDisposable`\r\n\r\n## \u003ca id=\"script-execution-order\"\u003e\u003c/a\u003eScript execution order\r\n\r\nSometimes you may face some strange exceptions about null containers, even with containers correctly configured. This may occur because of the [Script Execution Order](http://docs.unity3d.com/Manual/class-ScriptExecution.html) of the injected scripts, which are being called before the \u003ca href=\"#quick-start\"\u003eContextRoot\u003c/a\u003e creates the containers.\r\n\r\nTo prevent this from happening, the execution order of the context root should be set by either clicking on the `Set execution order` button on the context root inspector or by accessing the menu `Edit \u003e Project Settings \u003e Script Execution Order` on Unity.\r\n\r\n## \u003ca id=\"performance\"\u003e\u003c/a\u003ePerformance\r\n\r\n*Adic* was created with speed in mind, using internal cache to minimize the use of [reflection](http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29) (which is usually slow), ensuring a good performance when resolving and injecting into objects - the container can resolve a 1.000 objects in 1ms\u003ca href=\"#about-performance-tests\"\u003e\\*\u003c/a\u003e.\r\n\r\nTo maximize performance:\r\n\r\n1. always bind all types that will be resolved/injected in the \u003ca href=\"#quick-start\"\u003eContextRoot\u003c/a\u003e, so *Adic* can generate cache of the objects and use that information during runtime.\r\n\r\n2. always create all game objects that will be used during runtime before the game starts. [Object pooling](https://unity3d.com/pt/learn/tutorials/modules/beginner/live-training-archive/object-pooling) can help achieve that and increase performance by creating (and injecting) game objects upfront and reusing them throughout the game.\r\n\r\n3. when injecting on `MonoBehaviour`, use scene wide injection during game start instead of per `MonoBehaviour` injection. Read \u003ca href=\"#monobehaviour-injection\"\u003eMonoBehaviour injection\u003c/a\u003e for more details about injecting on the entire scene.\r\n\r\n4. if you have more than one container on the same scene, it's possible to share cache between them. To do so, create an instance of `Adic.Cache.ReflectionCache` and pass it to any container you create:\r\n\r\n```cs\r\nusing UnityEngine;\r\n\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// Game context root.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class GameRoot : Adic.ContextRoot {\r\n\t\tpublic override void SetupContainers() {\r\n\t\t\t//Create the reflection cache.\r\n\t\t\tvar cache = new ReflectionCache();\r\n\r\n\t\t\t//Create a new container.\r\n\t\t\tvar container1 = this.AddContainer(new InjectionContainer(cache));\r\n\r\n\t\t\t//Container configurations and bindings...\r\n\r\n\t\t\t//Create a new container.\r\n\t\t\tvar container2 = this.AddContainer(new InjectionContainer(cache));\r\n\r\n\t\t\t//Container configurations and bindings...\r\n\t\t}\r\n\r\n\t\tpublic override void Init() {\r\n\t\t\t//Init the game.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n\u003csup\u003e\u003ca id=\"about-performance-tests\"\u003e\\*\u003c/a\u003e See *Tests/Editor/SpeedTest.cs* for more details on performance tests. Tested on a MacBook Pro late 2014 (i7 2.5/3.7 GHz).\u003c/sup\u003e\r\n\r\n\u003csup\u003e\\- A thousand simple resolves in 1ms\u003c/sup\u003e\u003cbr\u003e\r\n\u003csup\u003e\\- A million simple resolves in 1330ms\u003c/sup\u003e\u003cbr\u003e\r\n\u003csup\u003e\\- A thousand complex resolves in 2ms\u003c/sup\u003e\u003cbr\u003e\r\n\u003csup\u003e\\- A million complex resolves in 2428ms\u003c/sup\u003e\r\n\r\n\u003csup\u003eA *simple resolve* is the resolution of a class without any `Inject` attributes.\u003c/sup\u003e\u003cbr\u003e\r\n\u003csup\u003eA *complex resolve* is the resolution of a class that is not bound to the container and has a `Inject` attribute in a field.\u003c/sup\u003e\r\n\r\n## \u003ca id=\"il2cpp-aot\"\u003e\u003c/a\u003eIL2CPP, AOT and code stripping\r\n\r\nWhen compiling to [AOT platforms](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) using IL2CPP (like iOS and WebGL), Unity performs *code stripping*, removing any code that is not being used. Although this is useful to reduce build size, it also affects classes that are only instantiated through *Adic*, since they are not created directly. To prevent non-inclusion of these classes, Unity provides the [`Preserve` attribute](http://docs.unity3d.com/ScriptReference/Scripting.PreserveAttribute.html), which should be added to all classes that are only created through the container.\r\n\r\n## \u003ca id=\"general-notes\"\u003e\u003c/a\u003eGeneral notes\r\n\r\n1. If an instance is not found, it will be resolved to NULL.\r\n2. Multiple injections must occur in an array of the desired type.\r\n3. Order of bindings is controlled by just reordering the bindings during container setup.\r\n4. Avoid singleton bindings of objects that will be destroyed during execution. This can lead to missing references in the container.\r\n5. Any transient object, once resolved, is not tracked by *Adic*. So, if you want e.g. a list of all prefabs that were resolved by the container, you'll have to store it manually. Singleton objects are kept inside the container, given there is just a single instance of them.\r\n6. *Adic* relies on Unity Test Tools for unit testing. You can download it at [Unity Asset Store](https://www.assetstore.unity3d.com/#!/content/13802).\r\n\r\n## \u003ca id=\"container-extensions\"\u003e\u003c/a\u003eExtensions\r\n\r\nExtensions are a way to enhance *Adic* without having to edit it to suit different needs. By using extensions, the core of *Adic* is kept agnostic, so it can be used on any C# environment.\r\n\r\n## \u003ca id=\"available-extensions\"\u003e\u003c/a\u003eAvailable extensions\r\n\r\n### \u003ca id=\"extension-bindings-printer\"\u003e\u003c/a\u003eBindings Printer\r\n\r\nPrints all bindings on any containers on the current context root. It must be executed on Play Mode.\r\n\r\nTo open the Bindings Printer windows, click on *Windows/Adic/Bindings Printer* menu.\r\n\r\n#### Format\r\n\r\n```\r\n[Container Type Full Name] (index: [Container Index on ContextRoot], [destroy on load/singleton])\r\n\r\n\t[For each binding]\r\n\tType: [Binding Type Full Name]\r\n\tBound to: [Bound To Type Full Name] ([type/instance])\r\n\tBinding type: [Transient/Singleton/Factory]\r\n\tIdentifier [Identifier/-]\r\n\tConditions: [yes/no]\r\n```\r\n\r\n#### Dependencies\r\n\r\n* \u003ca href=\"#extension-context-root\"\u003eContext Root\u003c/a\u003e\r\n\r\n### \u003ca id=\"extension-bindings-setup\"\u003e\u003c/a\u003eBindings Setup\r\n\r\nProvides a convenient place to setup bindings and reuse them in different containers and scenes.\r\n\r\n#### Configuration\r\n\r\nPlease see \u003ca href=\"#bindings-setup\"\u003eBindings setup\u003c/a\u003e for more information.\r\n\r\n#### Dependencies\r\n\r\nNone\r\n\r\n### \u003ca id=\"extension-commander\"\u003e\u003c/a\u003eCommander\r\n\r\nProvides dispatching of commands, with pooling for better performance.\r\n\r\nFor more information on commands, see \u003ca href=\"#using-commands\"\u003eUsing commands\u003c/a\u003e.\r\n\r\n#### Configuration\r\n\r\nRegister the extension on any containers that will use it:\r\n\r\n```cs\r\n//Create the container.\r\nthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t//Register any extensions the container may use.\r\n\t.RegisterExtension\u003cCommanderContainerExtension\u003e();\r\n```\r\n\r\nIf you use `IDiposable` or `IUpdatable` events, also register the \u003ca href=\"#extension-event-caller\"\u003eEvent Caller\u003c/a\u003e extension:\r\n\r\n```cs\r\n//Create the container.\r\nthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t//Register any extensions the container may use.\r\n\t.RegisterExtension\u003cCommanderContainerExtension\u003e()\r\n\t.RegisterExtension\u003cEventCallerContainerExtension\u003e();\r\n```\r\n\r\n#### Dependencies\r\n\r\n* \u003ca href=\"#extension-event-caller\"\u003eEvent Caller\u003c/a\u003e\r\n\r\n### \u003ca id=\"extension-context-root\"\u003e\u003c/a\u003eContext Root\r\n\r\nProvides an entry point for the game on Unity.\r\n\r\n#### Configuration\r\n\r\nPlease see \u003ca href=\"#quick-start\"\u003eQuick start\u003c/a\u003e for more information.\r\n\r\n#### Dependencies\r\n\r\nNone\r\n\r\n### \u003ca id=\"extension-event-caller\"\u003e\u003c/a\u003eEvent Caller\r\n\r\nCalls events on classes that implement certain interfaces. The classes must be bound to a container.\r\n\r\n#### Available events\r\n\r\n##### Update\r\n\r\nCalls `Update()` method on classes that implement `Adic.IUpdatable` interface. It's not called when the game is paused.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My updateable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : Adic.IUpdatable {\r\n\t\tpublic void Update() {\r\n\t\t\t//Update code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### LateUpdate\r\n\r\nCalls `LateUpdate()` method on classes that implement `Adic.ILateUpdatable` interface. It's not called when the game is paused.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My late updateable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : Adic.ILateUpdatable {\r\n\t\tpublic void LateUpdate() {\r\n\t\t\t//Late update code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### FixedUpdate\r\n\r\nCalls `FixedUpdate()` method on classes that implement `Adic.IFixedUpdatable` interface. It's called even when the game is paused.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My fixed updateable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : Adic.IFixedUpdatable {\r\n\t\tpublic void FixedUpdate() {\r\n\t\t\t//Fixed update code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### IPausable\r\n\r\nCalls `OnApplicationPause()` method on classes that implement `Adic.IPausable` interface.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My pausable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : Adic.IPausable {\r\n\t\tpublic void OnApplicationPause(bool isPaused) {\r\n\t\t\t//Called when the application is paused.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### IFocusable\r\n\r\nCalls `OnApplicationFocus()` method on classes that implement `Adic.IFocusable` interface.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My focusable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : Adic.IFocusable {\r\n\t\tpublic void OnApplicationFocus(hasFocus) {\r\n\t\t\t//Called when the application focus is changing.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### IQuitable\r\n\r\nCalls `OnApplicationQuit()` method on classes that implement `Adic.IQuitable` interface.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My quitable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : Adic.IQuitable {\r\n\t\tpublic void OnApplicationQuit() {\r\n\t\t\t//Called when the application quits.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n##### Dispose\r\n\r\nWhen a scene is destroyed, calls `Dispose()` method on classes that implement `System.IDisposable` interface.\r\n\r\n```cs\r\nnamespace MyNamespace {\r\n\t/// \u003csummary\u003e\r\n\t/// My disposable class.\r\n\t/// \u003c/summary\u003e\r\n\tpublic class MyClass : System.IDisposable {\r\n\t\tpublic void Dispose() {\r\n\t\t\t//Dispose code.\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n#### Configuration\r\n\r\nRegister the extension on any containers that will use it:\r\n\r\n```cs\r\n//Create the container.\r\nthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t//Register any extensions the container may use.\r\n\t.RegisterExtension\u003cEventCallerContainerExtension\u003e();ge\r\n```\r\n\r\n#### Notes\r\n\r\n1. Currently, any objects that are updateable are not removed from the update's list when they're not in use anymore. So, it's recommended to implement the `Adic.IUpdatable` interface only on singleton or transient objects that will live until the scene is destroyed;\r\n2. When the scene is destroyed, the update's list is cleared. So, any objects that will live between scenes that implement the `Adic.IUpdatable` interface will not be readded to the list. **It's recommeded to use updateable objects only on the context of a single scene**.\r\n3. Be aware of singleton objects on containers that will live through scenes. Eventually these objects may try to use references that may not exist anymore.\r\n\r\n#### Dependencies\r\n\r\nNone\r\n\r\n### \u003ca id=\"extension-mono-injection\"\u003e\u003c/a\u003eMono Injection\r\n\r\nAllows injection on `MonoBehaviour` by providing an `Inject()` method.\r\n\r\n#### Configuration\r\n\r\nPlease see \u003ca href=\"#monobehaviour-injection\"\u003eMonoBehaviour injection\u003c/a\u003e for more information.\r\n\r\n#### Dependencies\r\n\r\n* \u003ca href=\"#extension-context-root\"\u003eContext Root\u003c/a\u003e\r\n\r\n### \u003ca id=\"extension-state-injection\"\u003e\u003c/a\u003eState Injection\r\n\r\nAllows injection on `StateMachineBehaviour` by providing an `Inject()` method.\r\n\r\n#### Configuration\r\n\r\nPlease see \u003ca id=\"statemachinebehaviour-injection\"\u003e\u003c/a\u003eStateMachineBehaviour injection\u003c/a\u003e for more information.\r\n\r\n#### Dependencies\r\n\r\n* \u003ca href=\"#extension-context-root\"\u003eContext Root\u003c/a\u003e\r\n* \u003ca href=\"#extension-mono-injection\"\u003eMono Injection\u003c/a\u003e\r\n\r\n### \u003ca id=\"extension-unity-binding\"\u003e\u003c/a\u003eUnity Binding\r\n\r\nProvides Unity bindings to the container.\r\n\r\nPlease see \u003ca href=\"#bindings\"\u003eBindings\u003c/a\u003e for more information.\r\n\r\n#### Configuration\r\n\r\nRegister the extension on any containers that you may use it:\r\n\r\n```cs\r\n//Create the container.\r\nthis.AddContainer\u003cInjectionContainer\u003e()\r\n\t//Register any extensions the container may use.\r\n\t.RegisterExtension\u003cUnityBindingContainerExtension\u003e();\r\n```\r\n\r\n#### Notes\r\n\r\n1. **ALWAYS CALL `Inject()` FROM 'Start'**! (use the \u003ca href=\"#extension-mono-injection\"\u003eMono Injection\u003c/a\u003e Extension).\r\n\r\n#### Dependencies\r\n\r\nNone\r\n\r\n## \u003ca id=\"creating-extensions\"\u003e\u003c/a\u003eCreating extensions\r\n\r\nExtensions on *Adic* can be created in 3 ways:\r\n\r\n1. Creating a framework extension extending the base APIs through their interfaces;\r\n2. Creating extension methods to any part of the framework;\r\n3. Creating a container extension, which allows for the interception of internal events, which can alter the inner workings of the framework.\r\n\r\n**Note 1:** always place the public parts of extensions into *Adic* namespace.\r\n**Note 2:** a container can have only a single instance of each extension.\r\n\r\nTo create a *container extension*, which can intercept internal *Adic* events, you have to:\r\n\r\n1\\. Create the extension class with `ContainerExtension` sufix.\r\n\r\n2\\. Implement `Adic.Container.IContainerExtension`.\r\n\r\n3\\. Subscribe to any events on the container on OnRegister method.\r\n\r\n```cs\r\npublic void OnRegister(IInjectionContainer container) {\r\n\tcontainer.beforeAddBinding += this.OnBeforeAddBinding;\r\n}\r\n```\r\n\r\n4\\. Unsubscribe to any events the extension may use on the container on OnUnregister method.\r\n\r\n```cs\r\npublic void OnUnregister(IInjectionContainer container) {\r\n\tcontainer.beforeAddBinding -= this.OnBeforeAddBinding;\r\n}\r\n```\r\n\r\n5\\. Use the `Init()` method to initialize the extension. It's always called after all extensions and bindings have been added to the container, so it can be used as a late initialization method that may rely on bindings that were not available during registration.\r\n\r\n## \u003ca id=\"container-events\"\u003e\u003c/a\u003eContainer events\r\n\r\nContainer events provide a way to intercept internal actions of the container and change its inner workings to suit the needs of your extension.\r\n\r\nAll events are available through `Adic.InjectionContainer`.\r\n\r\n### \u003ca id=\"binder-events\"\u003e\u003c/a\u003eBinder events\r\n\r\n* `beforeAddBinding`: occurs before a binding is added.\r\n* `afterAddBinding`: occurs after a binding is added.\r\n* `beforeRemoveBinding`: occurs before a binding is removed.\r\n* `afterRemoveBinding`: occurs after a binding is removed.\r\n\r\n### \u003ca id=\"injector-events\"\u003e\u003c/a\u003eInjector events\r\n\r\n* `beforeResolve`: occurs before a type is resolved.\r\n* `afterResolve`: occurs after a type is resolved.\r\n* `bindingEvaluation`: occurs when a binding is available for resolution.\r\n* `bindingResolution`: occures when a binding is resolved to an instance.\r\n* `beforeInject`: occurs before an instance receives injection.\r\n* `afterInject`: occurs after an instance receives injection.\r\n\r\n## \u003ca id=\"binaries\"\u003e\u003c/a\u003eBinaries\r\n\r\nIf you need compiled binaries of *Adic*, look for them at the [releases page](https://github.com/intentor/adic/releases) (starting from version [2.13](https://github.com/intentor/adic/releases/tag/v2.13)).\r\n\r\nThe project is divided into 2 binaries:\r\n\r\n1. **Adic.Framework.dll**: main framework, decoupled from Unity.\r\n2. **Adic.Extensions.dll** Unity extensions.\r\n\r\n## \u003ca id=\"examples\"\u003e\u003c/a\u003eExamples\r\n\r\nThere are some examples that are bundled to the main package that teach the basics and beyond of *Adic*.\r\n\r\n### 1. Hello World\r\n\r\nExemplifies the basics of how to setup a scene for dependency injection using the ContextRoot.\r\n\r\n### 2. Binding Game Objects\r\n\r\nExemplifies how to bind components to new and existing game objects and allows them to share dependencies.\r\n\r\n### 3. Using conditions\r\n\r\nExemplifies the use of condition identifiers on injections.\r\n\r\n### 4. Prefabs\r\n\r\nExemplifies how to bind to prefabs and the use of method injection as a second constructor.\r\n\r\n### 5. Commander\r\n\r\nExemplifies the use of commands through a simple spawner of a prefab.\r\n\r\n### 6. Bindings Setup\r\n\r\nExemplifies the use of bindings setups to better organize the bindings for a container.\r\n\r\n### 7. Factory\r\n\r\nExemplifies the use of a factory to create and position cubes as a matrix.\r\n\r\n### 8. Unity Events\r\n\r\nExemplifies the use of Unity events on regular classes.\r\n\r\n## \u003ca id=\"changelog\"\u003e\u003c/a\u003eChangelog\r\n\r\nPlease see [CHANGELOG.txt](src/Assets/Adic/CHANGELOG.txt).\r\n\r\n## \u003ca id=\"support\"\u003e\u003c/a\u003eSupport\r\n\r\nFound a bug? Please create an issue on the [GitHub project page](https://github.com/intentor/adic/issues) or send a pull request if you have a fix or extension.\r\n\r\nYou can also send me a message at support@intentor.com.br to discuss more obscure matters about *Adic*.\r\n\r\n## \u003ca id=\"license\"\u003e\u003c/a\u003eLicense\r\n\r\nLicensed under the [The MIT License (MIT)](http://opensource.org/licenses/MIT). Please see [LICENSE](LICENSE) for more information.\r\n","funding_links":[],"categories":["C\\#","Open Source Repositories","Open Source Packages"],"sub_categories":["Dependency Injection","Framework"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintentor%2Fadic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintentor%2Fadic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintentor%2Fadic/lists"}