module HardWire::Root
Overview
A "Global" namespaced Container.
Consumers of the library can use this without creating their own.
We can also use it as an example of our macros, for documentation purposes.
Included Modules
Defined in:
hardwire.crClass Method Summary
- .registered?(type : Class, tags : String) : Bool
- .registered?(type : Class) : Bool
-
.registrations
Store all registrations, which are mainly used to give nice errors for duplicate registrations
Macro Summary
-
register(path, lifecycle = :singleton, tags = nil, &block)
Create a new registration from the passed type, lifecycle, and tags
-
singleton(path, tags = nil, &block)
Register a singleton dependency.
-
singleton(path, &block)
Register a singleton dependency.
-
transient(path, tags = nil, &block)
Register a transient dependency.
-
transient(path, &block)
Register a transient dependency.
Class Method Detail
Store all registrations, which are mainly used to give nice errors for duplicate registrations
Users can also run their own checks at runtime for length, structure, etc.
Macro Detail
Create a new registration from the passed type, lifecycle, and tags
Registration is essentially making a constructor method (self.resolve
) for the dependency,
that lives on the container.
resolves are differentiated by signature, rather than any other dynamic feature, so incoming calls route to the correct method without any dynamic-ness.
There are also some checks that get carried out in the registration to catch errors up front
- We keep a class var,
@@registrations
, which contains a stringified version of this dependency. This is used for making sure things have been registered/not registered twice. You can get this using the self.dependencies method - Tags are converted into classes, so that they can be passed around at compile time. This means you'll get missing const errors when you fail to register properly, but it should be clear why.