Skip to main content

Registration

A registration is an attribute on the container class: [Singleton<EspressoMachine>] tells the container to build an EspressoMachine and share it. Lifetimes explain the three lifetime attributes. This section covers everything else you can tell the container: how to build a service, how to wrap or combine services, how to choose between several implementations, and how to register many types or whole bundles at once.

Pick the page for your task​

You want toUseExplained on
Build a service with your own code, or register an object you already haveFactory or Instance on the lifetime attributeFactories and instances
Run code when an instance is activated or released, without putting it into the serviceOnActivated and OnReleaseLifecycle hooks
Add logging, retries or caching around a service without changing it[Decorate]Decorators
Fan one call out to every implementation of a service[Composite]Composites
Register several implementations of one service and pick one per consumerKey, WhenInjectedInto or [FromKey]Keyed services
Register a generic service once for every type argument the graph usesThe typeof form with an unbound genericOpen generics
Register every type that matches a marker or a naming convention[Scan]Scanning
Bundle registrations and reuse them in several containers[Module] and [Import]Modules
Ship a module from a library that keeps its implementations internal[Module] in the libraryShipping modules from a library
Reuse a production container in tests and replace only some servicesExtends on [Container]Extending containers

The attribute reference lists every attribute with all its options and defaults.

Where to go next​