diff --git a/source/poodinis/registration.d b/source/poodinis/registration.d index e494f46..f2ea281 100644 --- a/source/poodinis/registration.d +++ b/source/poodinis/registration.d @@ -73,3 +73,15 @@ public Registration newInstance(Registration registration) { registration.registationScope = new NewInstanceScope(registration.instantiatableType); return registration; } + +class ExistingInstanceScope : RegistrationScope { + Object instance = null; + + this(Object instance) { + this.instance = instance; + } + + public Object getInstance() { + return instance; + } +} diff --git a/test/poodinis/registrationtest.d b/test/poodinis/registrationtest.d index ce33aac..7bb3ad1 100644 --- a/test/poodinis/registrationtest.d +++ b/test/poodinis/registrationtest.d @@ -51,4 +51,13 @@ version(unittest) { assert(registration is chainedRegistration, "Registration returned by scope setting is not the same as the registration being set"); } + // Test getting instance from existing instance scope + unittest { + Registration registration = new Registration(null, null); + TestType expectedInstance = new TestType(); + registration.registationScope = new ExistingInstanceScope(expectedInstance); + auto actualInstance = registration.getInstance(); + assert(expectedInstance is actualInstance, "Registration with existing instance did not return given instance"); + } + } \ No newline at end of file