mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Change reference into class, makes it more easily passed as reference
This commit is contained in:
parent
64e25715cf
commit
2bced68e43
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue