Add new instance registration scope

This commit is contained in:
Mike Bierlee 2014-05-20 23:31:28 +02:00
parent aed449e565
commit 8b5122ad91
2 changed files with 22 additions and 0 deletions

View file

@ -56,3 +56,15 @@ public Registration singleInstance(Registration registration) {
registration.registationScope = new SingleInstanceScope(registration.instantiatableType);
return registration;
}
class NewInstanceScope : RegistrationScope {
TypeInfo_Class instantiatableType = null;
this(TypeInfo_Class instantiatableType) {
this.instantiatableType = instantiatableType;
}
public Object getInstance() {
return instantiatableType.create();
}
}

View file

@ -31,4 +31,14 @@ version(unittest) {
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");
}
// 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");
}
}