Let container create instance factory instead of scopes

This commit is contained in:
Mike Bierlee 2016-08-17 22:37:02 +02:00
parent 6b3b23a376
commit 831e38cb56
3 changed files with 3 additions and 4 deletions

View file

@ -24,6 +24,7 @@ debug {
import poodinis.registration; import poodinis.registration;
import poodinis.autowire; import poodinis.autowire;
import poodinis.context; import poodinis.context;
import poodinis.factory;
/** /**
* Exception thrown when errors occur while resolving a type in a dependency container. * 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); auto newRegistration = new AutowiredRegistration!ConcreteType(registeredType, this);
newRegistration.instanceFactory = new InstanceFactory();
newRegistration.singleInstance(); newRegistration.singleInstance();
static if (!is(SuperType == ConcreteType)) { static if (!is(SuperType == ConcreteType)) {

View file

@ -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. * new instances every time they are resolved. The factory method will be called repeatedly.
*/ */
struct Prototype {} struct Prototype {}

View file

@ -67,7 +67,6 @@ class Registration {
* Effectively makes the given registration a singleton. * Effectively makes the given registration a singleton.
*/ */
public Registration singleInstance(Registration registration) { public Registration singleInstance(Registration registration) {
registration.instanceFactory = new InstanceFactory();
registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.yes); registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.yes);
return registration; 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. * Scopes registrations to return a new instance every time the given registration is resolved.
*/ */
public Registration newInstance(Registration registration) { public Registration newInstance(Registration registration) {
registration.instanceFactory = new InstanceFactory();
registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.no); registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.no);
return registration; 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. * Scopes registrations to return the given instance every time the given registration is resolved.
*/ */
public Registration existingInstance(Registration registration, Object instance) { public Registration existingInstance(Registration registration, Object instance) {
registration.instanceFactory = new InstanceFactory();
registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.yes, instance); registration.instanceFactory.factoryParameters = InstanceFactoryParameters(registration.instanceType, CreatesSingleton.yes, instance);
return registration; return registration;
} }