diff --git a/source/poodinis/registration.d b/source/poodinis/registration.d index 876a2bb..37928e6 100644 --- a/source/poodinis/registration.d +++ b/source/poodinis/registration.d @@ -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(); + } +} diff --git a/test/poodinis/registrationtest.d b/test/poodinis/registrationtest.d index df11762..136939b 100644 --- a/test/poodinis/registrationtest.d +++ b/test/poodinis/registrationtest.d @@ -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"); + } + } \ No newline at end of file