mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add registration scope for existing instances
This commit is contained in:
parent
abdcd39e9e
commit
bb0a8d5746
|
@ -73,3 +73,15 @@ public Registration newInstance(Registration registration) {
|
|||
registration.registationScope = new NewInstanceScope(registration.instantiatableType);
|
||||
return registration;
|
||||
}
|
||||
|
||||
class ExistingInstanceScope : RegistrationScope {
|
||||
Object instance = null;
|
||||
|
||||
this(Object instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public Object getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,13 @@ version(unittest) {
|
|||
assert(registration is chainedRegistration, "Registration returned by scope setting is not the same as the registration being set");
|
||||
}
|
||||
|
||||
// Test getting instance from existing instance scope
|
||||
unittest {
|
||||
Registration registration = new Registration(null, null);
|
||||
TestType expectedInstance = new TestType();
|
||||
registration.registationScope = new ExistingInstanceScope(expectedInstance);
|
||||
auto actualInstance = registration.getInstance();
|
||||
assert(expectedInstance is actualInstance, "Registration with existing instance did not return given instance");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue