sqrs-inversify
MOVED TO @brainhubeu/sqrs-inversify
This package provides helpers for using sqrs with InversifyJS library.
Usage
SQRS Module
SQRS module registers all handler providers and default implementation of the buses.
;;; ; container.loadSQRSModule; // Will resolve to DefaultCommandBus;
ContainerBuilder
ContainerBuilder
is a helper class that allows you to use InversifyJS without decorators in type safe manner.
Example usage of ContainerBuilder
:
;; // Assuming CreateNoteCommand, NoteRepository are declared ;; builder.registerCommandHandlerCreateNoteCommandHandler; // Or using a module
It can be used with classes that have static field called dependencies
, e.g.:
The type of dependencies should be Dependencies
imported from sqrs
module. This type reflects arguments of the constructor and requires correct order and number of identifiers of type DependencyIdentifier<T>
, e.g.:
; ;;
When you change the order of constructor arguments or their types, dependencies will cause an error guarding the types that are injected.
To register a type that has dependencies
static field use registerType
method.
;;; ;; ; builder.registerTypebarId, Bar;
ContainerBuilder
exposes methods that allow for easy registration of:
- command handlers
- query handlers
- event handlers
To register a CommandHandler
implementation add static fields dependencies
and type
to the class. The type
field represents the type of command that this command handler handles, e.g.
/* * same as * containerBuilder.registerType( * commandHandlerId(CommandTypes.CreateNote), * CreateNoteCommandHandler * ) */containerBuilder.registerCommandHandlerCreateNoteCommandHandler
To register a QueryHandler
implementation add static fields dependencies
and queryName
to the class. The queryName
field represents the name of query that this handler handles, e.g.
/* * same as * containerBuilder.registerType( * queryHandlerId(QueryNames.GetNotes), * GetNotesQueryHandler * ) */containerBuilder.registerQueryHandlerGetNotesQueryHandler
To register an EventHandler
implementation add static fields dependencies
and type
to the class. The type
field represents the type of event that this handler handles or an array of types that this handler handles, e.g.
/* * same as calling following for each event type * containerBuilder.registerType( * eventHandlerId(eventType), * NoteCreatedEventHandler * ) */containerBuilder.registerEventHandlerNoteCreatedEventHandler