The point is the usage of DI-container in a proper way.
Add in Packages/manifest.json
to dependencies
:
"com.danand.simplecontainer": "https://github.com/Danand/SimpleContainer.git?path=SimpleContainer.Unity/Assets#0.7.1-beta.4",
From local repository
"com.danand.simplecontainer": "file:///D/repos/SimpleContainer/.git?path=SimpleContainer.Unity/Assets#0.7.1-beta.4",
From local working copy
"com.danand.simplecontainer": "file:D:/repos/SimpleContainer/SimpleContainer.Unity/Assets",
What is the difference?
Local repository is resolved just like normal Git repository with optionally specified revision.
Local working copy is being copied "as is" into dependent project, without running any Git process.
- Add
UnityProjectRoot
component to any object in hierarchy. - Reference
SimpleContainer.Core
andSimpleContainer.Unity
assemblies to your installer assembly via Assembly Definitions). - Implement your own
MonoInstaller
and add it as component too (example project below). - Reference
MonoInstaller
toUnityProjectRoot
via inspector. - Run.
- Do not use
DontDestroyOnLoad()
to pass container through different scenes. UseLoadSceneMode.Single
for "immortal" objects (e.g. managers, services, etc.), andLoadSceneMode.Additive
for presentation layer (e.g. gameplay, UI, etc.). Quite good alternative is to use separateUnityProjectRoot
per each loaded scene. - Prefer constructor injection over any other. Yeah, that means less usage of
MonoBehaviour
dependants. - Do not put dependencies on container. It will be perfect, if you did not have any
using SimpleContainer;
in your needy classes. - Use custom
Inject
attribute (example below). - You may move your installers to a separate assembly (via
.asmdef
) for stronger container usage protection. - If you really want to inject into
MonoBehaviour
without explicit registration – useMonoRegistrator
.
See example project included into this repository. Also you may open it with Unity and run.
See contribution note.
- Clean up repository
- Set up CI
- Optimize resolving
- Refactor container interface