Document public API of module "registration"

This commit is contained in:
Mike Bierlee 2015-02-21 16:11:43 +01:00
parent 8ee25abc58
commit f9c2e257c7

View file

@ -1,6 +1,10 @@
/** /**
* Poodinis Dependency Injection Framework * This module contains objects for defining and scoping dependency registrations.
* Copyright 2014-2015 Mike Bierlee *
* Authors:
* Mike Bierlee, m.bierlee@lostmoment.com
* Copyright: 2014-2015 Mike Bierlee
* License:
* This software is licensed under the terms of the MIT license. * This software is licensed under the terms of the MIT license.
* The full terms of the license can be found in the LICENSE file. * The full terms of the license can be found in the LICENSE file.
*/ */
@ -75,6 +79,11 @@ class SingleInstanceScope : CreationScope {
} }
} }
/**
* Scopes registrations to return the same instance every time a given registration is resolved.
*
* Effectively makes the given registration a singleton.
*/
public Registration singleInstance(Registration registration) { public Registration singleInstance(Registration registration) {
registration.registationScope = new SingleInstanceScope(registration.instantiatableType); registration.registationScope = new SingleInstanceScope(registration.instantiatableType);
return registration; return registration;
@ -95,6 +104,9 @@ class NewInstanceScope : CreationScope {
} }
} }
/**
* Scopes registrations to return a new instance every time the given registration is resolved.
*/
public Registration newInstance(Registration registration) { public Registration newInstance(Registration registration) {
registration.registationScope = new NewInstanceScope(registration.instantiatableType); registration.registationScope = new NewInstanceScope(registration.instantiatableType);
return registration; return registration;
@ -115,6 +127,9 @@ class ExistingInstanceScope : CreationScope {
} }
} }
/**
* Scopes registrations to return the given instance every time the given registration is resolved.
*/
public Registration existingInstance(Registration registration, Object instance) { public Registration existingInstance(Registration registration, Object instance) {
registration.registationScope = new ExistingInstanceScope(instance); registration.registationScope = new ExistingInstanceScope(instance);
return registration; return registration;