From 8b5122ad91bab1c72207f11d06cb0f9ad296809b Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 20 May 2014 23:31:28 +0200 Subject: [PATCH] Add new instance registration scope --- source/poodinis/registration.d | 12 ++++++++++++ test/poodinis/registrationtest.d | 10 ++++++++++ 2 files changed, 22 insertions(+) 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