mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add scope setter for new instance scope
This commit is contained in:
parent
8b5122ad91
commit
abdcd39e9e
|
@ -68,3 +68,8 @@ class NewInstanceScope : RegistrationScope {
|
|||
return instantiatableType.create();
|
||||
}
|
||||
}
|
||||
|
||||
public Registration newInstance(Registration registration) {
|
||||
registration.registationScope = new NewInstanceScope(registration.instantiatableType);
|
||||
return registration;
|
||||
}
|
||||
|
|
|
@ -103,4 +103,13 @@ version(unittest) {
|
|||
assert(instance1 is instance2);
|
||||
}
|
||||
|
||||
// Test resolve new instance for type
|
||||
unittest {
|
||||
auto container = new Container();
|
||||
container.register!(TestClass)().newInstance();
|
||||
auto instance1 = container.resolve!(TestClass);
|
||||
auto instance2 = container.resolve!(TestClass);
|
||||
assert(instance1 !is instance2);
|
||||
}
|
||||
|
||||
}
|
|
@ -41,4 +41,14 @@ version(unittest) {
|
|||
assert(instance1 !is instance2, "Registration with new instance scope did not return a different instance");
|
||||
}
|
||||
|
||||
// Test set new instance scope using scope setter
|
||||
unittest {
|
||||
Registration registration = new Registration(null, typeid(TestType));
|
||||
auto chainedRegistration = registration.newInstance();
|
||||
auto instance1 = registration.getInstance();
|
||||
auto instance2 = registration.getInstance();
|
||||
assert(instance1 !is instance2, "Registration with new instance scope did not return a different instance");
|
||||
assert(registration is chainedRegistration, "Registration returned by scope setting is not the same as the registration being set");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue