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.cr

Constant Summary

REGISTRATIONS = [] of String

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.

Class Method Summary

Macro Summary

Class Method Detail

def self.registered?(target : Class, tags : String = "") : Bool #

[View source]

Macro Detail

macro register(path, lifecycle = :singleton, tags = nil, &block) #

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 const, REGISTRATIONS, which contains a stringified version of this dependency. This is used for making sure things have been registered/not registered twice.
  • 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.

[View source]
macro singleton(path, tags = nil, &block) #

Register a singleton dependency.


[View source]
macro singleton(path, &block) #

Register a singleton dependency.


[View source]
macro transient(path, tags = nil, &block) #

Register a transient dependency.


[View source]
macro transient(path, &block) #

Register a transient dependency.


[View source]