mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Let container create instance factory instead of scopes
This commit is contained in:
parent
6b3b23a376
commit
831e38cb56
|
@ -24,6 +24,7 @@ debug {
|
|||
import poodinis.registration;
|
||||
import poodinis.autowire;
|
||||
import poodinis.context;
|
||||
import poodinis.factory;
|
||||
|
||||
/**
|
||||
* Exception thrown when errors occur while resolving a type in a dependency container.
|
||||
|
@ -147,6 +148,7 @@ synchronized class DependencyContainer {
|
|||
}
|
||||
|
||||
auto newRegistration = new AutowiredRegistration!ConcreteType(registeredType, this);
|
||||
newRegistration.instanceFactory = new InstanceFactory();
|
||||
newRegistration.singleInstance();
|
||||
|
||||
static if (!is(SuperType == ConcreteType)) {
|
||||
|
|
|
@ -38,7 +38,7 @@ struct RegisterByType(Type) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Components with the prototype registration will be scoped as dependencies which will created
|
||||
* Components with the prototype registration will be scoped as dependencies which will create
|
||||
* new instances every time they are resolved. The factory method will be called repeatedly.
|
||||
*/
|
||||
struct Prototype {}
|
||||
|
|
|
@ -67,7 +67,6 @@ class Registration {
|
|||
* Effectively makes the given registration a singleton.
|
||||
*/
|
||||
public Registration singleInstance(Registration registration) {
|
||||
registration.instanceFactory = new InstanceFactory();
|
||||
registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.yes);
|
||||
return registration;
|
||||
}
|
||||
|
@ -76,7 +75,6 @@ public Registration singleInstance(Registration registration) {
|
|||
* Scopes registrations to return a new instance every time the given registration is resolved.
|
||||
*/
|
||||
public Registration newInstance(Registration registration) {
|
||||
registration.instanceFactory = new InstanceFactory();
|
||||
registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.no);
|
||||
return registration;
|
||||
}
|
||||
|
@ -85,7 +83,6 @@ public Registration newInstance(Registration registration) {
|
|||
* Scopes registrations to return the given instance every time the given registration is resolved.
|
||||
*/
|
||||
public Registration existingInstance(Registration registration, Object instance) {
|
||||
registration.instanceFactory = new InstanceFactory();
|
||||
registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.yes, instance);
|
||||
return registration;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue