Register Plain C# Type
There are various ways to use Register. Let's take the following complex type as an example.
Register Concrete Type#
It can resolve like this:
Register as Interface#
It can resolve like this:
Register as multiple Interface#
It can resolve like this:
Register all implemented interfaces automatically#
It can resolve like this:
Register all implemented interfaces and concrete type#
It can resolve like this:
Register lifecycle marker interfaces#
note
This is similar to Register<GameController>(Lifetime.Singleton).AsImplementedInterfaces()
If you want to customize the exception handling for entry points, you can register a callback with the following.
If you have multiple EntryPoints, you have the option to use the following declaration as grouping.
This is the same as:
See the Plain C# Entry point section for more information.
Register instance#
note
RegisterIntance always has a Scoped lifetime, so it has no arguments.
It can resolve like this:
Register instance as interface#
Use As* declarations.
Register instance to set up from delegate#
Instance creation can be delegated to a lambda expression or another method or class.
It can resolve like this:
The first argument that can be used in the expression is IObjectResolver.
Using this, we can retrieve and use the registered object.
IObjectResolver.Instantiate can also be used to generate GameObjects executed inject.
See Use Container directory more information.
note
These delegates will be executed only once during scope construction. If you want to create an instance at any time during runtime, please refer to Register Factory.
Register type-specific parameters#
If the types are not unique, but you have a dependency you want to inject at startup, you can use the following:
Or, you can name a paramter with a key.
It can resolve like this:
This Register only works when being injected into SomeService.