Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 954 Bytes

token-registration.md

File metadata and controls

48 lines (32 loc) · 954 Bytes

Token registration

value can be a class definition, constant or a function

container.register('key', value)

new instance (default)

container.register('key2', value).asPrototype()

as singleton (use the same instance)

container.register('key3', value).asSingleton()

register with context: @Inject('paramKey') ... it will replace to 'otherKey'

container.register('key4', value)
    .asSingleton()
    .withContext({'paramKey': 'otherKey', 'paramKey2': 'otherKey2'})

register constant

container.register('key4', 'some constant').asConstant()

registrate by type (if you dont want to enable auto creaton you can still use this)

container.registerTypes([MyClass, Myclass2])

factory

container.register('factoryKey', FactoryClass).asFactory();
container.register('factoryResult', String).asFactoryResult('factoryKey');