diff --git a/source/poodinis/container.d b/source/poodinis/container.d index 23bb80b..066a68e 100644 --- a/source/poodinis/container.d +++ b/source/poodinis/container.d @@ -44,9 +44,9 @@ class Container { checkValidity!(InterfaceType)(registeredType, instantiatableType); } - Registration newRegistration = { registeredType, instantiatableType }; + Registration newRegistration = new Registration(registeredType, instantiatableType); newRegistration.singleInstance(); - registrations[newRegistration.registeredType] = newRegistration; + registrations[registeredType] = newRegistration; return newRegistration; } diff --git a/source/poodinis/registration.d b/source/poodinis/registration.d index e438441..876a2bb 100644 --- a/source/poodinis/registration.d +++ b/source/poodinis/registration.d @@ -1,10 +1,15 @@ module poodinis.registration; -struct Registration { +class Registration { TypeInfo registeredType = null; TypeInfo_Class instantiatableType = null; RegistrationScope registationScope = null; + this(TypeInfo registeredType, TypeInfo_Class instantiatableType) { + this.registeredType = registeredType; + this.instantiatableType = instantiatableType; + } + public Object getInstance() { if (registationScope is null) { throw new NoScopeDefinedException(registeredType); @@ -47,7 +52,7 @@ class SingleInstanceScope : RegistrationScope { } } -public Registration singleInstance(ref Registration registration) { +public Registration singleInstance(Registration registration) { registration.registationScope = new SingleInstanceScope(registration.instantiatableType); return registration; } diff --git a/test/poodinis/registrationtest.d b/test/poodinis/registrationtest.d index d74781f..df11762 100644 --- a/test/poodinis/registrationtest.d +++ b/test/poodinis/registrationtest.d @@ -8,14 +8,14 @@ version(unittest) { // Test getting instance without scope defined throws exception unittest { - Registration registration = Registration(); + Registration registration = new Registration(null, null); registration.registeredType = typeid(TestType); assertThrown!(NoScopeDefinedException)(registration.getInstance()); } // Test getting instance from single instance scope unittest { - Registration registration = Registration(); + Registration registration = new Registration(null, null); registration.registationScope = new SingleInstanceScope(typeid(TestType)); auto instance1 = registration.getInstance(); auto instance2 = registration.getInstance(); @@ -24,8 +24,7 @@ version(unittest) { // Test set single instance scope using scope setter unittest { - Registration registration = Registration(); - registration.instantiatableType = typeid(TestType); + Registration registration = new Registration(null, typeid(TestType)); auto chainedRegistration = registration.singleInstance(); auto instance1 = registration.getInstance(); auto instance2 = registration.getInstance();