mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add new instance registration scope
This commit is contained in:
parent
aed449e565
commit
8b5122ad91
|
@ -56,3 +56,15 @@ public Registration singleInstance(Registration registration) {
|
||||||
registration.registationScope = new SingleInstanceScope(registration.instantiatableType);
|
registration.registationScope = new SingleInstanceScope(registration.instantiatableType);
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NewInstanceScope : RegistrationScope {
|
||||||
|
TypeInfo_Class instantiatableType = null;
|
||||||
|
|
||||||
|
this(TypeInfo_Class instantiatableType) {
|
||||||
|
this.instantiatableType = instantiatableType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getInstance() {
|
||||||
|
return instantiatableType.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,4 +31,14 @@ version(unittest) {
|
||||||
assert(instance1 is instance2, "Registration with single instance scope did not return the same instance");
|
assert(instance1 is instance2, "Registration with single instance scope did not return the same instance");
|
||||||
assert(registration is chainedRegistration, "Registration returned by scope setting is not the same as the registration being set");
|
assert(registration is chainedRegistration, "Registration returned by scope setting is not the same as the registration being set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test getting instance from new instance scope
|
||||||
|
unittest {
|
||||||
|
Registration registration = new Registration(null, null);
|
||||||
|
registration.registationScope = new NewInstanceScope(typeid(TestType));
|
||||||
|
auto instance1 = registration.getInstance();
|
||||||
|
auto instance2 = registration.getInstance();
|
||||||
|
assert(instance1 !is instance2, "Registration with new instance scope did not return a different instance");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue