mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-14 19:54:00 +01:00
Get rid of public access specifiers
They are default in D
This commit is contained in:
parent
87c036d543
commit
adbd913b24
10
TUTORIAL.md
10
TUTORIAL.md
|
@ -255,13 +255,13 @@ An application context is defined as follows:
|
||||||
|
|
||||||
```d
|
```d
|
||||||
class Context : ApplicationContext {
|
class Context : ApplicationContext {
|
||||||
public override void registerDependencies(shared(DependencyContainer) container) {
|
override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
container.register!SomeClass;
|
container.register!SomeClass;
|
||||||
container.register!(SomeInterface, SomeOtherClass).newInstance();
|
container.register!(SomeInterface, SomeOtherClass).newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public SomeLibraryClass libraryClass() {
|
SomeLibraryClass libraryClass() {
|
||||||
return new SomeLibraryClass("This class uses a constructor parameter of a built-in type so I have to register it through an application context");
|
return new SomeLibraryClass("This class uses a constructor parameter of a built-in type so I have to register it through an application context");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,12 +299,12 @@ class Context : ApplicationContext {
|
||||||
@Inject
|
@Inject
|
||||||
private SomeOtherClass someOtherClass;
|
private SomeOtherClass someOtherClass;
|
||||||
|
|
||||||
public override void registerDependencies(shared(DependencyContainer) container) {
|
override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
container.register!SomeClass;
|
container.register!SomeClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public SomeLibraryClass libraryClass() {
|
SomeLibraryClass libraryClass() {
|
||||||
return new SomeLibraryClass(someClass, someOtherClass);
|
return new SomeLibraryClass(someClass, someOtherClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ class Context : ApplicationContext {
|
||||||
@Component
|
@Component
|
||||||
@Prototype // Will create a new instance every time the dependency is resolved.
|
@Prototype // Will create a new instance every time the dependency is resolved.
|
||||||
@RegisterByType!SomeInterface // Registers the dependency by the specified super type instead of the return type
|
@RegisterByType!SomeInterface // Registers the dependency by the specified super type instead of the return type
|
||||||
public SomeClass someClass() {
|
SomeClass someClass() {
|
||||||
return new SomeClass();
|
return new SomeClass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import std.stdio;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
|
||||||
class SecurityAuditor {
|
class SecurityAuditor {
|
||||||
public void submitAudit() {
|
void submitAudit() {
|
||||||
writeln("Hmmmyes I have received your audit. It is.... adequate.");
|
writeln("Hmmmyes I have received your audit. It is.... adequate.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,12 @@ class SecurityAuditor {
|
||||||
class SuperSecurityDevice {
|
class SuperSecurityDevice {
|
||||||
private int seed;
|
private int seed;
|
||||||
|
|
||||||
public this() {
|
this() {
|
||||||
auto randomGenerator = Random(unpredictableSeed);
|
auto randomGenerator = Random(unpredictableSeed);
|
||||||
seed = uniform(0, 999, randomGenerator);
|
seed = uniform(0, 999, randomGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getPassword() {
|
string getPassword() {
|
||||||
return to!string(seed) ~ "t1m3sp13!!:";
|
return to!string(seed) ~ "t1m3sp13!!:";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class SecurityManager {
|
||||||
|
|
||||||
@Inject @OptionalDependency private SecurityAuditor auditor;
|
@Inject @OptionalDependency private SecurityAuditor auditor;
|
||||||
|
|
||||||
public void doAudit() {
|
void doAudit() {
|
||||||
if (auditor !is null) {
|
if (auditor !is null) {
|
||||||
auditor.submitAudit();
|
auditor.submitAudit();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,17 +12,17 @@ import std.stdio;
|
||||||
class TownSquare {
|
class TownSquare {
|
||||||
@Inject private MarketStall marketStall;
|
@Inject private MarketStall marketStall;
|
||||||
|
|
||||||
public void makeSound() {
|
void makeSound() {
|
||||||
marketStall.announceGoodsForSale();
|
marketStall.announceGoodsForSale();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Goods {
|
interface Goods {
|
||||||
public string getGoodsName();
|
string getGoodsName();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Fish : Goods {
|
class Fish : Goods {
|
||||||
public override string getGoodsName() {
|
override string getGoodsName() {
|
||||||
return "Fish";
|
return "Fish";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class MarketStall {
|
||||||
this.goods = goods;
|
this.goods = goods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void announceGoodsForSale() {
|
void announceGoodsForSale() {
|
||||||
writeln(goods.getGoodsName() ~ " for sale!");
|
writeln(goods.getGoodsName() ~ " for sale!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,12 @@ class MarketStall {
|
||||||
class ExampleApplicationContext : ApplicationContext {
|
class ExampleApplicationContext : ApplicationContext {
|
||||||
@Inject private Goods goods;
|
@Inject private Goods goods;
|
||||||
|
|
||||||
public override void registerDependencies(shared(DependencyContainer) container) {
|
override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
container.register!(Goods, Fish);
|
container.register!(Goods, Fish);
|
||||||
container.register!TownSquare;
|
container.register!TownSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component public MarketStall marketStall() {
|
@Component MarketStall marketStall() {
|
||||||
return new MarketStall(goods);
|
return new MarketStall(goods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,23 +10,23 @@ import poodinis;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
interface Pie {
|
interface Pie {
|
||||||
public void eat();
|
void eat();
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlueBerryPie : Pie {
|
class BlueBerryPie : Pie {
|
||||||
public override void eat() {
|
override void eat() {
|
||||||
writeln("Nom nom nom. I like this one!");
|
writeln("Nom nom nom. I like this one!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ApplePie : Pie {
|
class ApplePie : Pie {
|
||||||
public override void eat() {
|
override void eat() {
|
||||||
writeln("Nom nom nom. These aren't real apples...");
|
writeln("Nom nom nom. These aren't real apples...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CardboardBoxPie : Pie {
|
class CardboardBoxPie : Pie {
|
||||||
public override void eat() {
|
override void eat() {
|
||||||
writeln("Nom nom nom. This... is not a pie.");
|
writeln("Nom nom nom. This... is not a pie.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class CardboardBoxPie : Pie {
|
||||||
class PieEater {
|
class PieEater {
|
||||||
@Inject private Pie[] pies;
|
@Inject private Pie[] pies;
|
||||||
|
|
||||||
public void eatThemAll() {
|
void eatThemAll() {
|
||||||
foreach (pie; pies) {
|
foreach (pie; pies) {
|
||||||
pie.eat();
|
pie.eat();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Scheduler {
|
||||||
this.calendar = calendar;
|
this.calendar = calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleJob() {
|
void scheduleJob() {
|
||||||
calendar.findOpenDate();
|
calendar.findOpenDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class Calendar {
|
||||||
this.hardwareClock = hardwareClock;
|
this.hardwareClock = hardwareClock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findOpenDate() {
|
void findOpenDate() {
|
||||||
hardwareClock.doThings();
|
hardwareClock.doThings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class HardwareClock {
|
||||||
throw new Exception("This constructor should not be used by Poodinis");
|
throw new Exception("This constructor should not be used by Poodinis");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doThings() {
|
void doThings() {
|
||||||
writeln("Things are being done!");
|
writeln("Things are being done!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,19 +10,19 @@ import poodinis;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
class ADependency {
|
class ADependency {
|
||||||
@PostConstruct public void postConstructor() {
|
@PostConstruct void postConstructor() {
|
||||||
writeln("The dependency is created.");
|
writeln("The dependency is created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void callMe() {
|
void callMe() {
|
||||||
writeln("The dependency was called.");
|
writeln("The dependency was called.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AClass {
|
class AClass {
|
||||||
@Inject public ADependency dependency; // Dependencies are autowired before the post-constructor is called.
|
@Inject ADependency dependency; // Dependencies are autowired before the post-constructor is called.
|
||||||
|
|
||||||
@PostConstruct public void postConstructor() {
|
@PostConstruct void postConstructor() {
|
||||||
writeln("The class is created.");
|
writeln("The class is created.");
|
||||||
if (dependency !is null) {
|
if (dependency !is null) {
|
||||||
writeln("The dependency is autowired.");
|
writeln("The dependency is autowired.");
|
||||||
|
@ -31,12 +31,12 @@ class AClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy public void preDestructor() {
|
@PreDestroy void preDestructor() {
|
||||||
writeln("The class is no longer registered with the container.");
|
writeln("The class is no longer registered with the container.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void main() {
|
void main() {
|
||||||
auto container = new shared DependencyContainer();
|
auto container = new shared DependencyContainer();
|
||||||
container.register!(ADependency).onConstructed((Object obj) {
|
container.register!(ADependency).onConstructed((Object obj) {
|
||||||
writeln("ADependency constructed");
|
writeln("ADependency constructed");
|
||||||
|
|
|
@ -10,17 +10,17 @@ import poodinis;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
interface Engine {
|
interface Engine {
|
||||||
public void engage();
|
void engage();
|
||||||
}
|
}
|
||||||
|
|
||||||
class FuelEngine : Engine {
|
class FuelEngine : Engine {
|
||||||
public void engage() {
|
void engage() {
|
||||||
writeln("VROOOOOOM!");
|
writeln("VROOOOOOM!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ElectricEngine : Engine {
|
class ElectricEngine : Engine {
|
||||||
public void engage() {
|
void engage() {
|
||||||
writeln("hummmmmmmm....");
|
writeln("hummmmmmmm....");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class HybridCar {
|
||||||
|
|
||||||
@Inject!ElectricEngine private Engine electricEngine;
|
@Inject!ElectricEngine private Engine electricEngine;
|
||||||
|
|
||||||
public void moveAtSpeed(KilometersPerHour speed) {
|
void moveAtSpeed(KilometersPerHour speed) {
|
||||||
if (speed <= 45) {
|
if (speed <= 45) {
|
||||||
electricEngine.engage();
|
electricEngine.engage();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -48,7 +48,7 @@ class HttpServer {
|
||||||
@MandatoryValue("http.keep_alive")
|
@MandatoryValue("http.keep_alive")
|
||||||
private int keepAliveTime; // A ResolveException is thrown when the value is not available, default assignments are not used.
|
private int keepAliveTime; // A ResolveException is thrown when the value is not available, default assignments are not used.
|
||||||
|
|
||||||
public void serve() {
|
void serve() {
|
||||||
writeln(format("Serving pages for %s:%s with max connection count of %s",
|
writeln(format("Serving pages for %s:%s with max connection count of %s",
|
||||||
hostName, port, maxConnections));
|
hostName, port, maxConnections));
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ private struct UseMemberType {
|
||||||
* ---
|
* ---
|
||||||
* class Car {
|
* class Car {
|
||||||
* @Autowire
|
* @Autowire
|
||||||
* public Engine engine;
|
* Engine engine;
|
||||||
* }
|
* }
|
||||||
* ---
|
* ---
|
||||||
*
|
*
|
||||||
|
@ -62,10 +62,10 @@ private struct UseMemberType {
|
||||||
*
|
*
|
||||||
* class HybridCar {
|
* class HybridCar {
|
||||||
* @Autowire!FuelEngine
|
* @Autowire!FuelEngine
|
||||||
* public Engine fuelEngine;
|
* Engine fuelEngine;
|
||||||
*
|
*
|
||||||
* @Autowire!ElectricEngine
|
* @Autowire!ElectricEngine
|
||||||
* public Engine electricEngine;
|
* Engine electricEngine;
|
||||||
* }
|
* }
|
||||||
* ---
|
* ---
|
||||||
* The members of an instance of "HybridCar" will now be autowired properly, because the autowire mechanism will
|
* The members of an instance of "HybridCar" will now be autowired properly, because the autowire mechanism will
|
||||||
|
@ -94,7 +94,7 @@ struct OptionalDependency {
|
||||||
* class Car {
|
* class Car {
|
||||||
* @Autowire
|
* @Autowire
|
||||||
* @AssignNewInstance
|
* @AssignNewInstance
|
||||||
* public Antenna antenna;
|
* Antenna antenna;
|
||||||
* }
|
* }
|
||||||
*---
|
*---
|
||||||
* antenna will always be assigned a new instance of class Antenna.
|
* antenna will always be assigned a new instance of class Antenna.
|
||||||
|
@ -117,7 +117,7 @@ private void printDebugAutowiredInstance(TypeInfo instanceType, void* instanceAd
|
||||||
*
|
*
|
||||||
* See_Also: Autowire
|
* See_Also: Autowire
|
||||||
*/
|
*/
|
||||||
public void autowire(Type)(shared(DependencyContainer) container, Type instance) {
|
void autowire(Type)(shared(DependencyContainer) container, Type instance) {
|
||||||
debug (poodinisVerbose) {
|
debug (poodinisVerbose) {
|
||||||
printDebugAutowiredInstance(typeid(Type), &instance);
|
printDebugAutowiredInstance(typeid(Type), &instance);
|
||||||
}
|
}
|
||||||
|
@ -276,19 +276,19 @@ private void printDebugValueInjection(TypeInfo instanceType,
|
||||||
* See_Also: DependencyContainer
|
* See_Also: DependencyContainer
|
||||||
* Deprecated: Using the global container is undesired. See DependencyContainer.getInstance().
|
* Deprecated: Using the global container is undesired. See DependencyContainer.getInstance().
|
||||||
*/
|
*/
|
||||||
public deprecated void globalAutowire(Type)(Type instance) {
|
deprecated void globalAutowire(Type)(Type instance) {
|
||||||
DependencyContainer.getInstance().autowire(instance);
|
DependencyContainer.getInstance().autowire(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AutowiredRegistration(RegistrationType : Object) : Registration {
|
class AutowiredRegistration(RegistrationType : Object) : Registration {
|
||||||
private shared(DependencyContainer) container;
|
private shared(DependencyContainer) container;
|
||||||
|
|
||||||
public this(TypeInfo registeredType, InstanceFactory instanceFactory,
|
this(TypeInfo registeredType, InstanceFactory instanceFactory,
|
||||||
shared(DependencyContainer) originatingContainer) {
|
shared(DependencyContainer) originatingContainer) {
|
||||||
super(registeredType, typeid(RegistrationType), instanceFactory, originatingContainer);
|
super(registeredType, typeid(RegistrationType), instanceFactory, originatingContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Object getInstance(
|
override Object getInstance(
|
||||||
InstantiationContext context = new AutowireInstantiationContext()) {
|
InstantiationContext context = new AutowireInstantiationContext()) {
|
||||||
enforce(!(originatingContainer is null),
|
enforce(!(originatingContainer is null),
|
||||||
"The registration's originating container is null. There is no way to resolve autowire dependencies.");
|
"The registration's originating container is null. There is no way to resolve autowire dependencies.");
|
||||||
|
@ -324,5 +324,5 @@ class AutowiredRegistration(RegistrationType : Object) : Registration {
|
||||||
}
|
}
|
||||||
|
|
||||||
class AutowireInstantiationContext : InstantiationContext {
|
class AutowireInstantiationContext : InstantiationContext {
|
||||||
public bool autowireInstance = true;
|
bool autowireInstance = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class RegistrationException : Exception {
|
||||||
/**
|
/**
|
||||||
* Options which influence the process of registering dependencies
|
* Options which influence the process of registering dependencies
|
||||||
*/
|
*/
|
||||||
public enum RegistrationOption {
|
enum RegistrationOption {
|
||||||
none = 0,
|
none = 0,
|
||||||
/**
|
/**
|
||||||
* Prevent a concrete type being registered on itself. With this option you will always need
|
* Prevent a concrete type being registered on itself. With this option you will always need
|
||||||
|
@ -68,7 +68,7 @@ public enum RegistrationOption {
|
||||||
/**
|
/**
|
||||||
* Options which influence the process of resolving dependencies
|
* Options which influence the process of resolving dependencies
|
||||||
*/
|
*/
|
||||||
public enum ResolveOption {
|
enum ResolveOption {
|
||||||
none = 0,
|
none = 0,
|
||||||
/**
|
/**
|
||||||
* Registers the type you're trying to resolve before returning it.
|
* Registers the type you're trying to resolve before returning it.
|
||||||
|
@ -146,7 +146,7 @@ synchronized class DependencyContainer {
|
||||||
*
|
*
|
||||||
* See_Also: singleInstance, newInstance, existingInstance
|
* See_Also: singleInstance, newInstance, existingInstance
|
||||||
*/
|
*/
|
||||||
public Registration register(ConcreteType)(RegistrationOption options = RegistrationOption.none) {
|
Registration register(ConcreteType)(RegistrationOption options = RegistrationOption.none) {
|
||||||
return register!(ConcreteType, ConcreteType)(options);
|
return register!(ConcreteType, ConcreteType)(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ synchronized class DependencyContainer {
|
||||||
*
|
*
|
||||||
* See_Also: singleInstance, newInstance, existingInstance, RegistrationOption
|
* See_Also: singleInstance, newInstance, existingInstance, RegistrationOption
|
||||||
*/
|
*/
|
||||||
public Registration register(SuperType, ConcreteType:
|
Registration register(SuperType, ConcreteType:
|
||||||
SuperType)(RegistrationOption options = RegistrationOption.none)
|
SuperType)(RegistrationOption options = RegistrationOption.none)
|
||||||
if (!is(ConcreteType == struct)) {
|
if (!is(ConcreteType == struct)) {
|
||||||
TypeInfo registeredType = typeid(SuperType);
|
TypeInfo registeredType = typeid(SuperType);
|
||||||
|
@ -271,7 +271,7 @@ synchronized class DependencyContainer {
|
||||||
* ---
|
* ---
|
||||||
* You need to use the resolve method which allows you to specify a qualifier.
|
* You need to use the resolve method which allows you to specify a qualifier.
|
||||||
*/
|
*/
|
||||||
public RegistrationType resolve(RegistrationType)(
|
RegistrationType resolve(RegistrationType)(
|
||||||
ResolveOption resolveOptions = ResolveOption.none)
|
ResolveOption resolveOptions = ResolveOption.none)
|
||||||
if (!is(RegistrationType == struct)) {
|
if (!is(RegistrationType == struct)) {
|
||||||
return resolve!(RegistrationType, RegistrationType)(resolveOptions);
|
return resolve!(RegistrationType, RegistrationType)(resolveOptions);
|
||||||
|
@ -303,7 +303,7 @@ synchronized class DependencyContainer {
|
||||||
* container.resolve!(Animal, Dog);
|
* container.resolve!(Animal, Dog);
|
||||||
* ---
|
* ---
|
||||||
*/
|
*/
|
||||||
public QualifierType resolve(RegistrationType, QualifierType:
|
QualifierType resolve(RegistrationType, QualifierType:
|
||||||
RegistrationType)(ResolveOption resolveOptions = ResolveOption.none)
|
RegistrationType)(ResolveOption resolveOptions = ResolveOption.none)
|
||||||
if (!is(QualifierType == struct)) {
|
if (!is(QualifierType == struct)) {
|
||||||
TypeInfo resolveType = typeid(RegistrationType);
|
TypeInfo resolveType = typeid(RegistrationType);
|
||||||
|
@ -381,7 +381,7 @@ synchronized class DependencyContainer {
|
||||||
* Animal[] animals = container.resolveAll!Animal;
|
* Animal[] animals = container.resolveAll!Animal;
|
||||||
* ---
|
* ---
|
||||||
*/
|
*/
|
||||||
public RegistrationType[] resolveAll(RegistrationType)(
|
RegistrationType[] resolveAll(RegistrationType)(
|
||||||
ResolveOption resolveOptions = ResolveOption.none) {
|
ResolveOption resolveOptions = ResolveOption.none) {
|
||||||
RegistrationType[] instances;
|
RegistrationType[] instances;
|
||||||
TypeInfo resolveType = typeid(RegistrationType);
|
TypeInfo resolveType = typeid(RegistrationType);
|
||||||
|
@ -435,7 +435,7 @@ synchronized class DependencyContainer {
|
||||||
/**
|
/**
|
||||||
* Clears all dependency registrations managed by this container.
|
* Clears all dependency registrations managed by this container.
|
||||||
*/
|
*/
|
||||||
public void clearAllRegistrations() {
|
void clearAllRegistrations() {
|
||||||
foreach (registrationsOfType; registrations) {
|
foreach (registrationsOfType; registrations) {
|
||||||
callPreDestructorsOfRegistrations(registrationsOfType);
|
callPreDestructorsOfRegistrations(registrationsOfType);
|
||||||
}
|
}
|
||||||
|
@ -452,7 +452,7 @@ synchronized class DependencyContainer {
|
||||||
* container.removeRegistration!Animal;
|
* container.removeRegistration!Animal;
|
||||||
* ---
|
* ---
|
||||||
*/
|
*/
|
||||||
public void removeRegistration(RegistrationType)() {
|
void removeRegistration(RegistrationType)() {
|
||||||
auto registrationsOfType = *(typeid(RegistrationType) in registrations);
|
auto registrationsOfType = *(typeid(RegistrationType) in registrations);
|
||||||
callPreDestructorsOfRegistrations(registrationsOfType);
|
callPreDestructorsOfRegistrations(registrationsOfType);
|
||||||
registrations.remove(typeid(RegistrationType));
|
registrations.remove(typeid(RegistrationType));
|
||||||
|
@ -470,28 +470,28 @@ synchronized class DependencyContainer {
|
||||||
/**
|
/**
|
||||||
* Apply persistent registration options which will be used everytime register() is called.
|
* Apply persistent registration options which will be used everytime register() is called.
|
||||||
*/
|
*/
|
||||||
public void setPersistentRegistrationOptions(RegistrationOption options) {
|
void setPersistentRegistrationOptions(RegistrationOption options) {
|
||||||
persistentRegistrationOptions = options;
|
persistentRegistrationOptions = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets all applied persistent registration options
|
* Unsets all applied persistent registration options
|
||||||
*/
|
*/
|
||||||
public void unsetPersistentRegistrationOptions() {
|
void unsetPersistentRegistrationOptions() {
|
||||||
persistentRegistrationOptions = RegistrationOption.none;
|
persistentRegistrationOptions = RegistrationOption.none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply persistent resolve options which will be used everytime resolve() is called.
|
* Apply persistent resolve options which will be used everytime resolve() is called.
|
||||||
*/
|
*/
|
||||||
public void setPersistentResolveOptions(ResolveOption options) {
|
void setPersistentResolveOptions(ResolveOption options) {
|
||||||
persistentResolveOptions = options;
|
persistentResolveOptions = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets all applied persistent resolve options
|
* Unsets all applied persistent resolve options
|
||||||
*/
|
*/
|
||||||
public void unsetPersistentResolveOptions() {
|
void unsetPersistentResolveOptions() {
|
||||||
persistentResolveOptions = ResolveOption.none;
|
persistentResolveOptions = ResolveOption.none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import poodinis.autowire : autowire;
|
||||||
import std.traits : hasUDA, ReturnType;
|
import std.traits : hasUDA, ReturnType;
|
||||||
|
|
||||||
class ApplicationContext {
|
class ApplicationContext {
|
||||||
public void registerDependencies(shared(DependencyContainer) container) {
|
void registerDependencies(shared(DependencyContainer) container) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ struct Prototype {
|
||||||
* It is mostly used for dependencies which come from an external library or when you don't
|
* It is mostly used for dependencies which come from an external library or when you don't
|
||||||
* want to use annotations to set-up dependencies in your classes.
|
* want to use annotations to set-up dependencies in your classes.
|
||||||
*/
|
*/
|
||||||
public void registerContext(Context : ApplicationContext)(shared(DependencyContainer) container) {
|
void registerContext(Context : ApplicationContext)(shared(DependencyContainer) container) {
|
||||||
auto context = new Context();
|
auto context = new Context();
|
||||||
context.registerDependencies(container);
|
context.registerDependencies(container);
|
||||||
context.registerContextComponents(container);
|
context.registerContextComponents(container);
|
||||||
|
@ -62,7 +62,7 @@ public void registerContext(Context : ApplicationContext)(shared(DependencyConta
|
||||||
autowire(container, context);
|
autowire(container, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerContextComponents(ApplicationContextType : ApplicationContext)(
|
void registerContextComponents(ApplicationContextType : ApplicationContext)(
|
||||||
ApplicationContextType context, shared(DependencyContainer) container) {
|
ApplicationContextType context, shared(DependencyContainer) container) {
|
||||||
foreach (memberName; __traits(allMembers, ApplicationContextType)) {
|
foreach (memberName; __traits(allMembers, ApplicationContextType)) {
|
||||||
foreach (overload; __traits(getOverloads, ApplicationContextType, memberName)) {
|
foreach (overload; __traits(getOverloads, ApplicationContextType, memberName)) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ class InstanceFactory {
|
||||||
factoryParameters = InstanceFactoryParameters();
|
factoryParameters = InstanceFactoryParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @property void factoryParameters(InstanceFactoryParameters factoryParameters) {
|
@property void factoryParameters(InstanceFactoryParameters factoryParameters) {
|
||||||
if (factoryParameters.factoryMethod is null) {
|
if (factoryParameters.factoryMethod is null) {
|
||||||
factoryParameters.factoryMethod = &this.createInstance;
|
factoryParameters.factoryMethod = &this.createInstance;
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,11 @@ class InstanceFactory {
|
||||||
_factoryParameters = factoryParameters;
|
_factoryParameters = factoryParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @property InstanceFactoryParameters factoryParameters() {
|
@property InstanceFactoryParameters factoryParameters() {
|
||||||
return _factoryParameters;
|
return _factoryParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getInstance() {
|
Object getInstance() {
|
||||||
if (_factoryParameters.createsSingleton && instance !is null) {
|
if (_factoryParameters.createsSingleton && instance !is null) {
|
||||||
debug (poodinisVerbose) {
|
debug (poodinisVerbose) {
|
||||||
printDebugUseExistingInstance();
|
printDebugUseExistingInstance();
|
||||||
|
|
|
@ -14,7 +14,7 @@ module poodinis.imports;
|
||||||
import std.meta : staticIndexOf;
|
import std.meta : staticIndexOf;
|
||||||
import std.traits : moduleName, TemplateArgsOf, isBuiltinType, isType;
|
import std.traits : moduleName, TemplateArgsOf, isBuiltinType, isType;
|
||||||
|
|
||||||
public static string createImportsString(Type, ParentTypeList...)() {
|
static string createImportsString(Type, ParentTypeList...)() {
|
||||||
string imports = `import ` ~ moduleName!Type ~ `;`;
|
string imports = `import ` ~ moduleName!Type ~ `;`;
|
||||||
static if (__traits(compiles, TemplateArgsOf!Type)) {
|
static if (__traits(compiles, TemplateArgsOf!Type)) {
|
||||||
foreach (TemplateArgType; TemplateArgsOf!Type) {
|
foreach (TemplateArgType; TemplateArgsOf!Type) {
|
||||||
|
|
|
@ -25,23 +25,23 @@ class Registration {
|
||||||
private InstanceFactory _instanceFactory;
|
private InstanceFactory _instanceFactory;
|
||||||
private void delegate() _preDestructor;
|
private void delegate() _preDestructor;
|
||||||
|
|
||||||
public @property registeredType() {
|
@property registeredType() {
|
||||||
return _registeredType;
|
return _registeredType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @property instanceType() {
|
@property instanceType() {
|
||||||
return _instanceType;
|
return _instanceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @property originatingContainer() {
|
@property originatingContainer() {
|
||||||
return _originatingContainer;
|
return _originatingContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @property instanceFactory() {
|
@property instanceFactory() {
|
||||||
return _instanceFactory;
|
return _instanceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @property preDestructor() {
|
@property preDestructor() {
|
||||||
return _preDestructor;
|
return _preDestructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class Registration {
|
||||||
this._instanceFactory = instanceFactory;
|
this._instanceFactory = instanceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getInstance(InstantiationContext context = new InstantiationContext()) {
|
Object getInstance(InstantiationContext context = new InstantiationContext()) {
|
||||||
if (linkedRegistration !is null) {
|
if (linkedRegistration !is null) {
|
||||||
return linkedRegistration.getInstance(context);
|
return linkedRegistration.getInstance(context);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ class Registration {
|
||||||
return instanceFactory.getInstance();
|
return instanceFactory.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Registration linkTo(Registration registration) {
|
Registration linkTo(Registration registration) {
|
||||||
this.linkedRegistration = registration;
|
this.linkedRegistration = registration;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ private void setFactoryParameters(Registration registration, InstanceFactoryPara
|
||||||
*
|
*
|
||||||
* This is not a registration scope. Typically used by Poodinis internally only.
|
* This is not a registration scope. Typically used by Poodinis internally only.
|
||||||
*/
|
*/
|
||||||
public Registration initializeFactoryType(Registration registration) {
|
Registration initializeFactoryType(Registration registration) {
|
||||||
auto params = registration.copyFactoryParameters();
|
auto params = registration.copyFactoryParameters();
|
||||||
params.instanceType = registration.instanceType;
|
params.instanceType = registration.instanceType;
|
||||||
registration.setFactoryParameters(params);
|
registration.setFactoryParameters(params);
|
||||||
|
@ -107,7 +107,7 @@ public Registration initializeFactoryType(Registration registration) {
|
||||||
*
|
*
|
||||||
* Effectively makes the given registration a singleton.
|
* Effectively makes the given registration a singleton.
|
||||||
*/
|
*/
|
||||||
public Registration singleInstance(Registration registration) {
|
Registration singleInstance(Registration registration) {
|
||||||
auto params = registration.copyFactoryParameters();
|
auto params = registration.copyFactoryParameters();
|
||||||
params.createsSingleton = CreatesSingleton.yes;
|
params.createsSingleton = CreatesSingleton.yes;
|
||||||
registration.setFactoryParameters(params);
|
registration.setFactoryParameters(params);
|
||||||
|
@ -117,7 +117,7 @@ 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) {
|
Registration newInstance(Registration registration) {
|
||||||
auto params = registration.copyFactoryParameters();
|
auto params = registration.copyFactoryParameters();
|
||||||
params.createsSingleton = CreatesSingleton.no;
|
params.createsSingleton = CreatesSingleton.no;
|
||||||
params.existingInstance = null;
|
params.existingInstance = null;
|
||||||
|
@ -128,7 +128,7 @@ 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) {
|
Registration existingInstance(Registration registration, Object instance) {
|
||||||
auto params = registration.copyFactoryParameters();
|
auto params = registration.copyFactoryParameters();
|
||||||
params.createsSingleton = CreatesSingleton.yes;
|
params.createsSingleton = CreatesSingleton.yes;
|
||||||
params.existingInstance = instance;
|
params.existingInstance = instance;
|
||||||
|
@ -139,7 +139,7 @@ public Registration existingInstance(Registration registration, Object instance)
|
||||||
/**
|
/**
|
||||||
* Scopes registrations to create new instances using the given initializer delegate.
|
* Scopes registrations to create new instances using the given initializer delegate.
|
||||||
*/
|
*/
|
||||||
public Registration initializedBy(T)(Registration registration, T delegate() initializer)
|
Registration initializedBy(T)(Registration registration, T delegate() initializer)
|
||||||
if (is(T == class) || is(T == interface)) {
|
if (is(T == class) || is(T == interface)) {
|
||||||
auto params = registration.copyFactoryParameters();
|
auto params = registration.copyFactoryParameters();
|
||||||
params.createsSingleton = CreatesSingleton.no;
|
params.createsSingleton = CreatesSingleton.no;
|
||||||
|
@ -151,7 +151,7 @@ public Registration initializedBy(T)(Registration registration, T delegate() ini
|
||||||
/**
|
/**
|
||||||
* Scopes registrations to create a new instance using the given initializer delegate. On subsequent resolves the same instance is returned.
|
* Scopes registrations to create a new instance using the given initializer delegate. On subsequent resolves the same instance is returned.
|
||||||
*/
|
*/
|
||||||
public Registration initializedOnceBy(T : Object)(Registration registration, T delegate() initializer) {
|
Registration initializedOnceBy(T : Object)(Registration registration, T delegate() initializer) {
|
||||||
auto params = registration.copyFactoryParameters();
|
auto params = registration.copyFactoryParameters();
|
||||||
params.createsSingleton = CreatesSingleton.yes;
|
params.createsSingleton = CreatesSingleton.yes;
|
||||||
params.factoryMethod = () => cast(Object) initializer();
|
params.factoryMethod = () => cast(Object) initializer();
|
||||||
|
@ -159,7 +159,7 @@ public Registration initializedOnceBy(T : Object)(Registration registration, T d
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string toConcreteTypeListString(Registration[] registrations) {
|
string toConcreteTypeListString(Registration[] registrations) {
|
||||||
auto concreteTypeListString = "";
|
auto concreteTypeListString = "";
|
||||||
foreach (registration; registrations) {
|
foreach (registration; registrations) {
|
||||||
if (concreteTypeListString.length > 0) {
|
if (concreteTypeListString.length > 0) {
|
||||||
|
|
|
@ -101,7 +101,7 @@ struct MandatoryValue {
|
||||||
* Examples:
|
* Examples:
|
||||||
* ---
|
* ---
|
||||||
* class MyIntInjector : ValueInjector!int {
|
* class MyIntInjector : ValueInjector!int {
|
||||||
* public override int get(string key) { ... }
|
* override int get(string key) { ... }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // In order to make the container use your injector, register it by interface:
|
* // In order to make the container use your injector, register it by interface:
|
||||||
|
|
|
@ -15,7 +15,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentB {
|
class ComponentB {
|
||||||
public @Inject ComponentA componentA;
|
@Inject ComponentA componentA;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InterfaceA {
|
interface InterfaceA {
|
||||||
|
@ -25,10 +25,10 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentD {
|
class ComponentD {
|
||||||
public @Inject InterfaceA componentC = null;
|
@Inject InterfaceA componentC = null;
|
||||||
private @Inject InterfaceA _privateComponentC = null;
|
private @Inject InterfaceA _privateComponentC = null;
|
||||||
|
|
||||||
public InterfaceA privateComponentC() {
|
InterfaceA privateComponentC() {
|
||||||
return _privateComponentC;
|
return _privateComponentC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,15 @@ version (unittest) {
|
||||||
};
|
};
|
||||||
|
|
||||||
class ComponentE {
|
class ComponentE {
|
||||||
@DummyAttribute public ComponentC componentC;
|
@DummyAttribute ComponentC componentC;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentDeclarationCocktail {
|
class ComponentDeclarationCocktail {
|
||||||
alias noomer = int;
|
alias noomer = int;
|
||||||
|
|
||||||
@Inject public ComponentA componentA;
|
@Inject ComponentA componentA;
|
||||||
|
|
||||||
public void doesNothing() {
|
void doesNothing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
~this() {
|
~this() {
|
||||||
|
@ -59,40 +59,40 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonkeyShine {
|
class MonkeyShine {
|
||||||
@Inject!ComponentX public InterfaceA component;
|
@Inject!ComponentX InterfaceA component;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BootstrapBootstrap {
|
class BootstrapBootstrap {
|
||||||
@Inject!ComponentX public InterfaceA componentX;
|
@Inject!ComponentX InterfaceA componentX;
|
||||||
|
|
||||||
@Inject!ComponentC public InterfaceA componentC;
|
@Inject!ComponentC InterfaceA componentC;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LordOfTheComponents {
|
class LordOfTheComponents {
|
||||||
@Inject public InterfaceA[] components;
|
@Inject InterfaceA[] components;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentCharlie {
|
class ComponentCharlie {
|
||||||
@Inject @AssignNewInstance public ComponentA componentA;
|
@Inject @AssignNewInstance ComponentA componentA;
|
||||||
}
|
}
|
||||||
|
|
||||||
class OuttaTime {
|
class OuttaTime {
|
||||||
@Inject @OptionalDependency public InterfaceA interfaceA;
|
@Inject @OptionalDependency InterfaceA interfaceA;
|
||||||
|
|
||||||
@Inject @OptionalDependency public ComponentA componentA;
|
@Inject @OptionalDependency ComponentA componentA;
|
||||||
|
|
||||||
@Inject @OptionalDependency public ComponentC[] componentCs;
|
@Inject @OptionalDependency ComponentC[] componentCs;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ValuedClass {
|
class ValuedClass {
|
||||||
@Value("values.int")
|
@Value("values.int")
|
||||||
public int intValue;
|
int intValue;
|
||||||
|
|
||||||
@Inject public ComponentA unrelated;
|
@Inject ComponentA unrelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestInjector : ValueInjector!int {
|
class TestInjector : ValueInjector!int {
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
assert(key == "values.int");
|
assert(key == "values.int");
|
||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestClassDeux : TestInterface {
|
class TestClassDeux : TestInterface {
|
||||||
@Inject public UnrelatedClass unrelated;
|
@Inject UnrelatedClass unrelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnrelatedClass {
|
class UnrelatedClass {
|
||||||
|
@ -121,46 +121,46 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentClass {
|
class ComponentClass {
|
||||||
@Inject public AutowiredClass autowiredClass;
|
@Inject AutowiredClass autowiredClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentCat {
|
class ComponentCat {
|
||||||
@Inject public ComponentMouse mouse;
|
@Inject ComponentMouse mouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComponentMouse {
|
class ComponentMouse {
|
||||||
@Inject public ComponentCat cat;
|
@Inject ComponentCat cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Eenie {
|
class Eenie {
|
||||||
@Inject public Meenie meenie;
|
@Inject Meenie meenie;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meenie {
|
class Meenie {
|
||||||
@Inject public Moe moe;
|
@Inject Moe moe;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Moe {
|
class Moe {
|
||||||
@Inject public Eenie eenie;
|
@Inject Eenie eenie;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Ittie {
|
class Ittie {
|
||||||
@Inject public Bittie bittie;
|
@Inject Bittie bittie;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Bittie {
|
class Bittie {
|
||||||
@Inject public Bunena banana;
|
@Inject Bunena banana;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Bunena {
|
class Bunena {
|
||||||
@Inject public Bittie bittie;
|
@Inject Bittie bittie;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SuperInterface {
|
interface SuperInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
class SuperImplementation : SuperInterface {
|
class SuperImplementation : SuperInterface {
|
||||||
@Inject public Bunena banana;
|
@Inject Bunena banana;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Color {
|
interface Color {
|
||||||
|
@ -173,28 +173,28 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Spiders {
|
class Spiders {
|
||||||
@Inject public TestInterface testMember;
|
@Inject TestInterface testMember;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Recursive {
|
class Recursive {
|
||||||
@Inject public Recursive recursive;
|
@Inject Recursive recursive;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Moolah {
|
class Moolah {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Wants {
|
class Wants {
|
||||||
@Inject public Moolah moolah;
|
@Inject Moolah moolah;
|
||||||
}
|
}
|
||||||
|
|
||||||
class John {
|
class John {
|
||||||
@Inject public Wants wants;
|
@Inject Wants wants;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Cocktail {
|
class Cocktail {
|
||||||
@Inject public Moolah moolah;
|
@Inject Moolah moolah;
|
||||||
|
|
||||||
public Red red;
|
Red red;
|
||||||
|
|
||||||
this(Red red) {
|
this(Red red) {
|
||||||
this.red = red;
|
this.red = red;
|
||||||
|
@ -202,7 +202,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Wallpaper {
|
class Wallpaper {
|
||||||
public Color color;
|
Color color;
|
||||||
|
|
||||||
this(Color color) {
|
this(Color color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
@ -240,9 +240,9 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class PostConstructionDependency {
|
class PostConstructionDependency {
|
||||||
public bool postConstructWasCalled = false;
|
bool postConstructWasCalled = false;
|
||||||
|
|
||||||
@PostConstruct public void callMeMaybe() {
|
@PostConstruct void callMeMaybe() {
|
||||||
postConstructWasCalled = true;
|
postConstructWasCalled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,9 +255,9 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ButThereWontBe : ThereWillBePostConstruction {
|
class ButThereWontBe : ThereWillBePostConstruction {
|
||||||
public bool postConstructWasCalled = false;
|
bool postConstructWasCalled = false;
|
||||||
|
|
||||||
public override void constructIt() {
|
override void constructIt() {
|
||||||
postConstructWasCalled = true;
|
postConstructWasCalled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,16 +268,16 @@ version (unittest) {
|
||||||
@Value("")
|
@Value("")
|
||||||
private int theNumber = 1;
|
private int theNumber = 1;
|
||||||
|
|
||||||
@PostConstruct public void doIt() {
|
@PostConstruct void doIt() {
|
||||||
assert(theNumber == 8783);
|
assert(theNumber == 8783);
|
||||||
assert(dependency !is null);
|
assert(dependency !is null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PreDestroyerOfFates {
|
class PreDestroyerOfFates {
|
||||||
public bool preDestroyWasCalled = false;
|
bool preDestroyWasCalled = false;
|
||||||
|
|
||||||
@PreDestroy public void callMeMaybe() {
|
@PreDestroy void callMeMaybe() {
|
||||||
preDestroyWasCalled = true;
|
preDestroyWasCalled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Banana {
|
class Banana {
|
||||||
public string color;
|
string color;
|
||||||
|
|
||||||
this(string color) {
|
this(string color) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
@ -308,19 +308,19 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Pear : Fruit {
|
class Pear : Fruit {
|
||||||
public override string getShape() {
|
override string getShape() {
|
||||||
return "Pear shaped";
|
return "Pear shaped";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Rabbit : Animal {
|
class Rabbit : Animal {
|
||||||
public override string getYell() {
|
override string getYell() {
|
||||||
return "Squeeeeeel";
|
return "Squeeeeeel";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Wolf : Animal {
|
class Wolf : Animal {
|
||||||
public override string getYell() {
|
override string getYell() {
|
||||||
return "Wooooooooooo";
|
return "Wooooooooooo";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWrapper {
|
class ClassWrapper {
|
||||||
public Object someClass;
|
Object someClass;
|
||||||
|
|
||||||
this(Object someClass) {
|
this(Object someClass) {
|
||||||
this.someClass = someClass;
|
this.someClass = someClass;
|
||||||
|
@ -340,7 +340,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWrapperWrapper {
|
class ClassWrapperWrapper {
|
||||||
public ClassWrapper wrapper;
|
ClassWrapper wrapper;
|
||||||
|
|
||||||
this(ClassWrapper wrapper) {
|
this(ClassWrapper wrapper) {
|
||||||
this.wrapper = wrapper;
|
this.wrapper = wrapper;
|
||||||
|
@ -348,11 +348,11 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class SimpleContext : ApplicationContext {
|
class SimpleContext : ApplicationContext {
|
||||||
public override void registerDependencies(shared(DependencyContainer) container) {
|
override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
container.register!CakeChart;
|
container.register!CakeChart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component public Apple apple() {
|
@Component Apple apple() {
|
||||||
return new Apple();
|
return new Apple();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,15 +363,15 @@ version (unittest) {
|
||||||
|
|
||||||
@Inject protected ClassWrapper classWrapper;
|
@Inject protected ClassWrapper classWrapper;
|
||||||
|
|
||||||
public override void registerDependencies(shared(DependencyContainer) container) {
|
override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
container.register!Apple;
|
container.register!Apple;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component public ClassWrapper wrapper() {
|
@Component ClassWrapper wrapper() {
|
||||||
return new ClassWrapper(apple);
|
return new ClassWrapper(apple);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component public ClassWrapperWrapper wrapperWrapper() {
|
@Component ClassWrapperWrapper wrapperWrapper() {
|
||||||
return new ClassWrapperWrapper(classWrapper);
|
return new ClassWrapperWrapper(classWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,47 +381,47 @@ version (unittest) {
|
||||||
|
|
||||||
@Inject private Apple apple;
|
@Inject private Apple apple;
|
||||||
|
|
||||||
@Component public ClassWrapper wrapper() {
|
@Component ClassWrapper wrapper() {
|
||||||
return new ClassWrapper(apple);
|
return new ClassWrapper(apple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestContext : ApplicationContext {
|
class TestContext : ApplicationContext {
|
||||||
|
|
||||||
@Component public Banana banana() {
|
@Component Banana banana() {
|
||||||
return new Banana("Yellow");
|
return new Banana("Yellow");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Apple apple() {
|
Apple apple() {
|
||||||
return new Apple();
|
return new Apple();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component @RegisterByType!Fruit public Pear pear() {
|
@Component @RegisterByType!Fruit Pear pear() {
|
||||||
return new Pear();
|
return new Pear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component @RegisterByType!Animal public Rabbit rabbit() {
|
@Component @RegisterByType!Animal Rabbit rabbit() {
|
||||||
return new Rabbit();
|
return new Rabbit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component @RegisterByType!Animal public Wolf wolf() {
|
@Component @RegisterByType!Animal Wolf wolf() {
|
||||||
return new Wolf();
|
return new Wolf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component @Prototype public PieChart pieChart() {
|
@Component @Prototype PieChart pieChart() {
|
||||||
return new PieChart();
|
return new PieChart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestImplementation : TestInterface {
|
class TestImplementation : TestInterface {
|
||||||
public string someContent = "";
|
string someContent = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
class SomeOtherClassThen {
|
class SomeOtherClassThen {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithConstructor {
|
class ClassWithConstructor {
|
||||||
public TestImplementation testImplementation;
|
TestImplementation testImplementation;
|
||||||
|
|
||||||
this(TestImplementation testImplementation) {
|
this(TestImplementation testImplementation) {
|
||||||
this.testImplementation = testImplementation;
|
this.testImplementation = testImplementation;
|
||||||
|
@ -429,8 +429,8 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithMultipleConstructors {
|
class ClassWithMultipleConstructors {
|
||||||
public SomeOtherClassThen someOtherClassThen;
|
SomeOtherClassThen someOtherClassThen;
|
||||||
public TestImplementation testImplementation;
|
TestImplementation testImplementation;
|
||||||
|
|
||||||
this(SomeOtherClassThen someOtherClassThen) {
|
this(SomeOtherClassThen someOtherClassThen) {
|
||||||
this.someOtherClassThen = someOtherClassThen;
|
this.someOtherClassThen = someOtherClassThen;
|
||||||
|
@ -443,8 +443,8 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithConstructorWithMultipleParameters {
|
class ClassWithConstructorWithMultipleParameters {
|
||||||
public SomeOtherClassThen someOtherClassThen;
|
SomeOtherClassThen someOtherClassThen;
|
||||||
public TestImplementation testImplementation;
|
TestImplementation testImplementation;
|
||||||
|
|
||||||
this(SomeOtherClassThen someOtherClassThen, TestImplementation testImplementation) {
|
this(SomeOtherClassThen someOtherClassThen, TestImplementation testImplementation) {
|
||||||
this.someOtherClassThen = someOtherClassThen;
|
this.someOtherClassThen = someOtherClassThen;
|
||||||
|
@ -453,7 +453,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithPrimitiveConstructor {
|
class ClassWithPrimitiveConstructor {
|
||||||
public SomeOtherClassThen someOtherClassThen;
|
SomeOtherClassThen someOtherClassThen;
|
||||||
|
|
||||||
this(string willNotBePicked) {
|
this(string willNotBePicked) {
|
||||||
}
|
}
|
||||||
|
@ -464,7 +464,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithEmptyConstructor {
|
class ClassWithEmptyConstructor {
|
||||||
public SomeOtherClassThen someOtherClassThen;
|
SomeOtherClassThen someOtherClassThen;
|
||||||
|
|
||||||
this() {
|
this() {
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithStructConstructor {
|
class ClassWithStructConstructor {
|
||||||
public SomeOtherClassThen someOtherClassThen;
|
SomeOtherClassThen someOtherClassThen;
|
||||||
|
|
||||||
this(Thing willNotBePicked) {
|
this(Thing willNotBePicked) {
|
||||||
}
|
}
|
||||||
|
@ -522,58 +522,58 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntInjector : ValueInjector!int {
|
class IntInjector : ValueInjector!int {
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
assert(key == "conf.stuffs");
|
assert(key == "conf.stuffs");
|
||||||
return 364;
|
return 364;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringInjector : ValueInjector!string {
|
class StringInjector : ValueInjector!string {
|
||||||
public override string get(string key) {
|
override string get(string key) {
|
||||||
assert(key == "conf.name");
|
assert(key == "conf.name");
|
||||||
return "Le Chef";
|
return "Le Chef";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThingInjector : ValueInjector!Thing {
|
class ThingInjector : ValueInjector!Thing {
|
||||||
public override Thing get(string key) {
|
override Thing get(string key) {
|
||||||
assert(key == "conf.thing");
|
assert(key == "conf.thing");
|
||||||
return Thing(8899);
|
return Thing(8899);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DefaultIntInjector : ValueInjector!int {
|
class DefaultIntInjector : ValueInjector!int {
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
throw new ValueNotAvailableException(key);
|
throw new ValueNotAvailableException(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MandatoryAvailableIntInjector : ValueInjector!int {
|
class MandatoryAvailableIntInjector : ValueInjector!int {
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
return 7466;
|
return 7466;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MandatoryUnavailableIntInjector : ValueInjector!int {
|
class MandatoryUnavailableIntInjector : ValueInjector!int {
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
throw new ValueNotAvailableException(key);
|
throw new ValueNotAvailableException(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DependencyInjectedIntInjector : ValueInjector!int {
|
class DependencyInjectedIntInjector : ValueInjector!int {
|
||||||
@Inject public Dependency dependency;
|
@Inject Dependency dependency;
|
||||||
|
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
return 2345;
|
return 2345;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CircularIntInjector : ValueInjector!int {
|
class CircularIntInjector : ValueInjector!int {
|
||||||
@Inject public ValueInjector!int dependency;
|
@Inject ValueInjector!int dependency;
|
||||||
|
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
count += 1;
|
count += 1;
|
||||||
if (count >= 3) {
|
if (count >= 3) {
|
||||||
return count;
|
return count;
|
||||||
|
@ -584,9 +584,9 @@ version (unittest) {
|
||||||
|
|
||||||
class ValueInjectedIntInjector : ValueInjector!int {
|
class ValueInjectedIntInjector : ValueInjector!int {
|
||||||
@Value("five")
|
@Value("five")
|
||||||
public int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
if (key == "five") {
|
if (key == "five") {
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
@ -596,9 +596,9 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DependencyValueInjectedIntInjector : ValueInjector!int {
|
class DependencyValueInjectedIntInjector : ValueInjector!int {
|
||||||
@Inject public ConfigWithDefaults config;
|
@Inject ConfigWithDefaults config;
|
||||||
|
|
||||||
public override int get(string key) {
|
override int get(string key) {
|
||||||
if (key == "conf.missing") {
|
if (key == "conf.missing") {
|
||||||
return 8899;
|
return 8899;
|
||||||
}
|
}
|
||||||
|
@ -620,7 +620,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClassWithTemplatedConstructorArg(T) {
|
class ClassWithTemplatedConstructorArg(T) {
|
||||||
public TemplatedComponent!T dependency;
|
TemplatedComponent!T dependency;
|
||||||
|
|
||||||
this(TemplatedComponent!T assignedDependency) {
|
this(TemplatedComponent!T assignedDependency) {
|
||||||
this.dependency = assignedDependency;
|
this.dependency = assignedDependency;
|
||||||
|
@ -641,17 +641,17 @@ version (unittest) {
|
||||||
|
|
||||||
class AutowiredMethod {
|
class AutowiredMethod {
|
||||||
@Inject
|
@Inject
|
||||||
public int lala() {
|
int lala() {
|
||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public int lala(int valla) {
|
int lala(int valla) {
|
||||||
return valla;
|
return valla;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithAutowireAttribute {
|
class WithAutowireAttribute {
|
||||||
public @Autowire ComponentA componentA;
|
@Autowire ComponentA componentA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ version (unittest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalStructInjector : ValueInjector!LocalStruct {
|
class LocalStructInjector : ValueInjector!LocalStruct {
|
||||||
public override LocalStruct get(string key) {
|
override LocalStruct get(string key) {
|
||||||
auto data = LocalStruct(true);
|
auto data = LocalStruct(true);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ version (unittest) {
|
||||||
|
|
||||||
class LocalClassWithStruct {
|
class LocalClassWithStruct {
|
||||||
@Value("")
|
@Value("")
|
||||||
public LocalStruct localStruct;
|
LocalStruct localStruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test injection of values
|
// Test injection of values
|
||||||
|
|
Loading…
Reference in a new issue