mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Merge remote-tracking branch 'origin/master' into develop
This commit is contained in:
commit
a8da958bfb
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2014-2016 Mike Bierlee
|
Copyright (c) 2014-2017 Mike Bierlee
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Poodinis Dependency Injection Framework
|
Poodinis Dependency Injection Framework
|
||||||
=======================================
|
=======================================
|
||||||
Version 8.0.0
|
Version 8.0.0
|
||||||
Copyright 2014-2016 Mike Bierlee
|
Copyright 2014-2017 Mike Bierlee
|
||||||
Licensed under the terms of the MIT license - See [LICENSE.txt](LICENSE.txt)
|
Licensed under the terms of the MIT license - See [LICENSE.txt](LICENSE.txt)
|
||||||
|
|
||||||
Master: [![Build Status](https://api.travis-ci.org/mbierlee/poodinis.png?branch=master)](https://travis-ci.org/mbierlee/poodinis) - Dev: [![Build Status](https://api.travis-ci.org/mbierlee/poodinis.png?branch=develop)](https://travis-ci.org/mbierlee/poodinis)
|
Master: [![Build Status](https://api.travis-ci.org/mbierlee/poodinis.png?branch=master)](https://travis-ci.org/mbierlee/poodinis) - Dev: [![Build Status](https://api.travis-ci.org/mbierlee/poodinis.png?branch=develop)](https://travis-ci.org/mbierlee/poodinis)
|
||||||
|
|
2
dub.json
2
dub.json
|
@ -3,7 +3,7 @@
|
||||||
"description" : "A dependency injection framework with support for autowiring.",
|
"description" : "A dependency injection framework with support for autowiring.",
|
||||||
"homepage": "http://lostmoment.com/open-source/poodinis",
|
"homepage": "http://lostmoment.com/open-source/poodinis",
|
||||||
"authors": ["Mike Bierlee"],
|
"authors": ["Mike Bierlee"],
|
||||||
"copyright": "Copyright 2014-2016 Mike Bierlee",
|
"copyright": "Copyright 2014-2017 Mike Bierlee",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,72 +1,72 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
import std.random;
|
import std.random;
|
||||||
import std.digest.md;
|
import std.digest.md;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
|
||||||
class SecurityAuditor {
|
class SecurityAuditor {
|
||||||
public void submitAudit() {
|
public void submitAudit() {
|
||||||
writeln("Hmmmyes I have received your audit. It is.... adequate.");
|
writeln("Hmmmyes I have received your audit. It is.... adequate.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SuperSecurityDevice {
|
class SuperSecurityDevice {
|
||||||
private int seed;
|
private int seed;
|
||||||
|
|
||||||
public this() {
|
public this() {
|
||||||
auto randomGenerator = Random(unpredictableSeed);
|
auto randomGenerator = Random(unpredictableSeed);
|
||||||
seed = uniform(0, 999, randomGenerator);
|
seed = uniform(0, 999, randomGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getPassword() {
|
public string getPassword() {
|
||||||
return to!string(seed) ~ "t1m3sp13!!:";
|
return to!string(seed) ~ "t1m3sp13!!:";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SecurityManager {
|
class SecurityManager {
|
||||||
@Autowire
|
@Autowire
|
||||||
private SuperSecurityDevice levelOneSecurity;
|
private SuperSecurityDevice levelOneSecurity;
|
||||||
|
|
||||||
@Autowire
|
@Autowire
|
||||||
@AssignNewInstance
|
@AssignNewInstance
|
||||||
private SuperSecurityDevice levelTwoSecurity;
|
private SuperSecurityDevice levelTwoSecurity;
|
||||||
|
|
||||||
@Autowire
|
@Autowire
|
||||||
@OptionalDependency
|
@OptionalDependency
|
||||||
private SecurityAuditor auditor;
|
private SecurityAuditor auditor;
|
||||||
|
|
||||||
public void doAudit() {
|
public void doAudit() {
|
||||||
if (auditor !is null) {
|
if (auditor !is null) {
|
||||||
auditor.submitAudit();
|
auditor.submitAudit();
|
||||||
} else {
|
} else {
|
||||||
writeln("I uh, will skip the audit for now...");
|
writeln("I uh, will skip the audit for now...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
auto dependencies = new shared DependencyContainer();
|
auto dependencies = new shared DependencyContainer();
|
||||||
dependencies.register!SuperSecurityDevice; // Registered with the default "Single instance" scope
|
dependencies.register!SuperSecurityDevice; // Registered with the default "Single instance" scope
|
||||||
dependencies.register!SecurityManager;
|
dependencies.register!SecurityManager;
|
||||||
|
|
||||||
auto manager = dependencies.resolve!SecurityManager;
|
auto manager = dependencies.resolve!SecurityManager;
|
||||||
|
|
||||||
writeln("Password for user one: " ~ manager.levelOneSecurity.getPassword());
|
writeln("Password for user one: " ~ manager.levelOneSecurity.getPassword());
|
||||||
writeln("Password for user two: " ~ manager.levelTwoSecurity.getPassword());
|
writeln("Password for user two: " ~ manager.levelTwoSecurity.getPassword());
|
||||||
|
|
||||||
if (manager.levelOneSecurity is manager.levelTwoSecurity) {
|
if (manager.levelOneSecurity is manager.levelTwoSecurity) {
|
||||||
writeln("SECURITY BREACH!!!!!"); // Should not be printed since levelTwoSecurity is a new instance.
|
writeln("SECURITY BREACH!!!!!"); // Should not be printed since levelTwoSecurity is a new instance.
|
||||||
} else {
|
} else {
|
||||||
writeln("Security okay!");
|
writeln("Security okay!");
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.doAudit(); // Will not cause the SecurityAuditor to print, since we didn't register a SecurityAuditor.
|
manager.doAudit(); // Will not cause the SecurityAuditor to print, since we didn't register a SecurityAuditor.
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +1,68 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
class TownSquare {
|
class TownSquare {
|
||||||
|
|
||||||
@Autowire
|
@Autowire
|
||||||
private MarketStall marketStall;
|
private MarketStall marketStall;
|
||||||
|
|
||||||
public void makeSound() {
|
public void makeSound() {
|
||||||
marketStall.announceGoodsForSale();
|
marketStall.announceGoodsForSale();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Goods {
|
interface Goods {
|
||||||
public string getGoodsName();
|
public string getGoodsName();
|
||||||
}
|
}
|
||||||
|
|
||||||
class Fish : Goods {
|
class Fish : Goods {
|
||||||
public override string getGoodsName() {
|
public override string getGoodsName() {
|
||||||
return "Fish";
|
return "Fish";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MarketStall {
|
class MarketStall {
|
||||||
private Goods goods;
|
private Goods goods;
|
||||||
|
|
||||||
this(Goods goods) {
|
this(Goods goods) {
|
||||||
this.goods = goods;
|
this.goods = goods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void announceGoodsForSale() {
|
public void announceGoodsForSale() {
|
||||||
writeln(goods.getGoodsName() ~ " for sale!");
|
writeln(goods.getGoodsName() ~ " for sale!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExampleApplicationContext : ApplicationContext {
|
class ExampleApplicationContext : ApplicationContext {
|
||||||
|
|
||||||
@Autowire
|
@Autowire
|
||||||
private Goods goods;
|
private Goods goods;
|
||||||
|
|
||||||
public override void registerDependencies(shared(DependencyContainer) container) {
|
public override void registerDependencies(shared(DependencyContainer) container) {
|
||||||
container.register!(Goods, Fish);
|
container.register!(Goods, Fish);
|
||||||
container.register!TownSquare;
|
container.register!TownSquare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public MarketStall marketStall() {
|
public MarketStall marketStall() {
|
||||||
return new MarketStall(goods);
|
return new MarketStall(goods);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
auto container = new shared DependencyContainer();
|
auto container = new shared DependencyContainer();
|
||||||
container.registerContext!ExampleApplicationContext;
|
container.registerContext!ExampleApplicationContext;
|
||||||
|
|
||||||
auto townSquare = container.resolve!TownSquare;
|
auto townSquare = container.resolve!TownSquare;
|
||||||
townSquare.makeSound();
|
townSquare.makeSound();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
interface Pie {
|
interface Pie {
|
||||||
public void eat();
|
public void eat();
|
||||||
}
|
}
|
||||||
|
|
||||||
class BlueBerryPie : Pie {
|
class BlueBerryPie : Pie {
|
||||||
public override void eat() {
|
public 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() {
|
public 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() {
|
public override void eat() {
|
||||||
writeln("Nom nom nom. This... is not a pie.");
|
writeln("Nom nom nom. This... is not a pie.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PieEater {
|
class PieEater {
|
||||||
@Autowire
|
@Autowire
|
||||||
private Pie[] pies;
|
private Pie[] pies;
|
||||||
|
|
||||||
public void eatThemAll() {
|
public void eatThemAll() {
|
||||||
foreach(pie ; pies) {
|
foreach(pie ; pies) {
|
||||||
pie.eat();
|
pie.eat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
auto dependencies = new shared DependencyContainer();
|
auto dependencies = new shared DependencyContainer();
|
||||||
dependencies.register!(Pie, BlueBerryPie);
|
dependencies.register!(Pie, BlueBerryPie);
|
||||||
dependencies.register!(Pie, ApplePie);
|
dependencies.register!(Pie, ApplePie);
|
||||||
dependencies.register!(Pie, CardboardBoxPie);
|
dependencies.register!(Pie, CardboardBoxPie);
|
||||||
dependencies.register!(PieEater);
|
dependencies.register!(PieEater);
|
||||||
|
|
||||||
auto eater = dependencies.resolve!PieEater;
|
auto eater = dependencies.resolve!PieEater;
|
||||||
eater.eatThemAll();
|
eater.eatThemAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +1,64 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Scheduler {
|
class Scheduler {
|
||||||
private Calendar calendar;
|
private Calendar calendar;
|
||||||
|
|
||||||
// All parameters will autmatically be assigned when Scheduler is created.
|
// All parameters will autmatically be assigned when Scheduler is created.
|
||||||
this(Calendar calendar) {
|
this(Calendar calendar) {
|
||||||
this.calendar = calendar;
|
this.calendar = calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleJob() {
|
public void scheduleJob() {
|
||||||
calendar.findOpenDate();
|
calendar.findOpenDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Calendar {
|
class Calendar {
|
||||||
private HardwareClock hardwareClock;
|
private HardwareClock hardwareClock;
|
||||||
|
|
||||||
// This constructor contains built-in type "int" and thus will not be used.
|
// This constructor contains built-in type "int" and thus will not be used.
|
||||||
this(int initialDateTimeStamp, HardwareClock hardwareClock) {
|
this(int initialDateTimeStamp, HardwareClock hardwareClock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This constructor is chosen instead as candidate for injection when Calendar is created.
|
// This constructor is chosen instead as candidate for injection when Calendar is created.
|
||||||
this(HardwareClock hardwareClock) {
|
this(HardwareClock hardwareClock) {
|
||||||
this.hardwareClock = hardwareClock;
|
this.hardwareClock = hardwareClock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findOpenDate() {
|
public void findOpenDate() {
|
||||||
hardwareClock.doThings();
|
hardwareClock.doThings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HardwareClock {
|
class HardwareClock {
|
||||||
// Parameterless constructors will halt any further selection of constructors.
|
// Parameterless constructors will halt any further selection of constructors.
|
||||||
this() {}
|
this() {}
|
||||||
|
|
||||||
// As a result, this constructor will not be used when HardwareClock is created.
|
// As a result, this constructor will not be used when HardwareClock is created.
|
||||||
this(Calendar calendar) {
|
this(Calendar calendar) {
|
||||||
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() {
|
public void doThings() {
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
writeln("Things are being done!");
|
writeln("Things are being done!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
import poodinis; // Locally imported to emphasize that classes do not depend on Poodinis.
|
import poodinis; // Locally imported to emphasize that classes do not depend on Poodinis.
|
||||||
|
|
||||||
auto dependencies = new shared DependencyContainer();
|
auto dependencies = new shared DependencyContainer();
|
||||||
dependencies.register!Scheduler;
|
dependencies.register!Scheduler;
|
||||||
dependencies.register!Calendar;
|
dependencies.register!Calendar;
|
||||||
dependencies.register!HardwareClock;
|
dependencies.register!HardwareClock;
|
||||||
|
|
||||||
auto scheduler = dependencies.resolve!Scheduler;
|
auto scheduler = dependencies.resolve!Scheduler;
|
||||||
scheduler.scheduleJob();
|
scheduler.scheduleJob();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,53 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
class ADependency {
|
class ADependency {
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void postConstructor() {
|
public void postConstructor() {
|
||||||
writeln("The dependency is created.");
|
writeln("The dependency is created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void callMe() {
|
public void callMe() {
|
||||||
writeln("The dependency was called.");
|
writeln("The dependency was called.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AClass {
|
class AClass {
|
||||||
@Autowire
|
@Autowire
|
||||||
public ADependency dependency; // Dependencies are autowired before the post-constructor is called.
|
public ADependency dependency; // Dependencies are autowired before the post-constructor is called.
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void postConstructor() {
|
public 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.");
|
||||||
} else {
|
} else {
|
||||||
writeln("The dependency was NOT autowired.");
|
writeln("The dependency was NOT autowired.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void preDestructor() {
|
public 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() {
|
public void main() {
|
||||||
auto container = new shared DependencyContainer();
|
auto container = new shared DependencyContainer();
|
||||||
container.register!ADependency;
|
container.register!ADependency;
|
||||||
container.register!AClass;
|
container.register!AClass;
|
||||||
auto instance = container.resolve!AClass; // Will cause the post constructor to be called.
|
auto instance = container.resolve!AClass; // Will cause the post constructor to be called.
|
||||||
container.removeRegistration!AClass; // Will cause the pre destructor to be called.
|
container.removeRegistration!AClass; // Will cause the pre destructor to be called.
|
||||||
|
|
||||||
// The instance won't be destroyed by the container and as long as there are references to it,
|
// The instance won't be destroyed by the container and as long as there are references to it,
|
||||||
// it will not be collected by the garbage collector either.
|
// it will not be collected by the garbage collector either.
|
||||||
instance.dependency.callMe();
|
instance.dependency.callMe();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
class Violin {
|
class Violin {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InstrumentPlayer {
|
interface InstrumentPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViolinPlayer : InstrumentPlayer {
|
class ViolinPlayer : InstrumentPlayer {
|
||||||
// Autowired concrete types can be registered on resolve
|
// Autowired concrete types can be registered on resolve
|
||||||
@Autowire
|
@Autowire
|
||||||
private Violin violin;
|
private Violin violin;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Orchestra {
|
class Orchestra {
|
||||||
// Autowired non-concrete types can be registered on resolved, given they have a qualifier.
|
// Autowired non-concrete types can be registered on resolved, given they have a qualifier.
|
||||||
@Autowire!ViolinPlayer
|
@Autowire!ViolinPlayer
|
||||||
private InstrumentPlayer violinPlayer;
|
private InstrumentPlayer violinPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
auto dependencies = new shared DependencyContainer();
|
auto dependencies = new shared DependencyContainer();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* By using the resolve option "registerBeforeResolving" you can register the resolved class
|
* By using the resolve option "registerBeforeResolving" you can register the resolved class
|
||||||
* immediately. Note that any autowired member will not automatically be registered as well.
|
* immediately. Note that any autowired member will not automatically be registered as well.
|
||||||
*/
|
*/
|
||||||
auto violinPlayer = dependencies.resolve!Violin(ResolveOption.registerBeforeResolving);
|
auto violinPlayer = dependencies.resolve!Violin(ResolveOption.registerBeforeResolving);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* You can make the resolve option persistent by setting it on the container with setPersistentResolveOptions().
|
* You can make the resolve option persistent by setting it on the container with setPersistentResolveOptions().
|
||||||
* This will register all resolved types and their autowired members (recursively).
|
* This will register all resolved types and their autowired members (recursively).
|
||||||
* Note that you will still get ResolveExceptions when a non-concrete type is autowired (without qualifier).
|
* Note that you will still get ResolveExceptions when a non-concrete type is autowired (without qualifier).
|
||||||
* In those cases you will still have to register those particular dependencies beforehand.
|
* In those cases you will still have to register those particular dependencies beforehand.
|
||||||
*/
|
*/
|
||||||
dependencies.setPersistentResolveOptions(ResolveOption.registerBeforeResolving);
|
dependencies.setPersistentResolveOptions(ResolveOption.registerBeforeResolving);
|
||||||
auto orchestra = dependencies.resolve!Orchestra;
|
auto orchestra = dependencies.resolve!Orchestra;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +1,64 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import poodinis;
|
import poodinis;
|
||||||
|
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.string;
|
import std.string;
|
||||||
|
|
||||||
class IntValueInjector : ValueInjector!int {
|
class IntValueInjector : ValueInjector!int {
|
||||||
int get(string key) {
|
int get(string key) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case "http.port":
|
case "http.port":
|
||||||
return 8080;
|
return 8080;
|
||||||
case "http.keep_alive":
|
case "http.keep_alive":
|
||||||
return 60;
|
return 60;
|
||||||
default:
|
default:
|
||||||
throw new ValueNotAvailableException(key);
|
throw new ValueNotAvailableException(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringValueInjector : ValueInjector!string {
|
class StringValueInjector : ValueInjector!string {
|
||||||
string get(string key) {
|
string get(string key) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case "http.hostname":
|
case "http.hostname":
|
||||||
return "acme.org";
|
return "acme.org";
|
||||||
default:
|
default:
|
||||||
throw new ValueNotAvailableException(key);
|
throw new ValueNotAvailableException(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpServer {
|
class HttpServer {
|
||||||
|
|
||||||
@Value("http.port")
|
@Value("http.port")
|
||||||
private int port = 80;
|
private int port = 80;
|
||||||
|
|
||||||
@Value("http.hostname")
|
@Value("http.hostname")
|
||||||
private string hostName = "localhost";
|
private string hostName = "localhost";
|
||||||
|
|
||||||
@Value("http.max_connections")
|
@Value("http.max_connections")
|
||||||
private int maxConnections = 1000; // Default assignment is kept because max_connections is not available within the injector
|
private int maxConnections = 1000; // Default assignment is kept because max_connections is not available within the injector
|
||||||
|
|
||||||
@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() {
|
public void serve() {
|
||||||
writeln(format("Serving pages for %s:%s with max connection count of %s", hostName, port, maxConnections));
|
writeln(format("Serving pages for %s:%s with max connection count of %s", hostName, port, maxConnections));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
auto dependencies = new shared DependencyContainer();
|
auto dependencies = new shared DependencyContainer();
|
||||||
dependencies.register!(ValueInjector!int, IntValueInjector);
|
dependencies.register!(ValueInjector!int, IntValueInjector);
|
||||||
dependencies.register!(ValueInjector!string, StringValueInjector);
|
dependencies.register!(ValueInjector!string, StringValueInjector);
|
||||||
dependencies.register!HttpServer;
|
dependencies.register!HttpServer;
|
||||||
|
|
||||||
auto server = dependencies.resolve!HttpServer;
|
auto server = dependencies.resolve!HttpServer;
|
||||||
server.serve(); // Prints "Serving pages for acme.org:8080 with max connection count of 1000"
|
server.serve(); // Prints "Serving pages for acme.org:8080 with max connection count of 1000"
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* Kenji Hara,
|
* Kenji Hara,
|
||||||
* Shoichi Kato,
|
* Shoichi Kato,
|
||||||
* Mike Bierlee (m.bierlee@lostmoment.com)
|
* Mike Bierlee (m.bierlee@lostmoment.com)
|
||||||
* Copyright: Copyright Digital Mars 2005 - 2009., Copyright Andrei Alexandrescu 2008-, Jonathan M Davis 2011-., 2014-2016 Mike Bierlee
|
* Copyright: Copyright Digital Mars 2005 - 2009., Copyright Andrei Alexandrescu 2008-, Jonathan M Davis 2011-., 2014-2017 Mike Bierlee
|
||||||
* License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0)
|
* License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Mike Bierlee, m.bierlee@lostmoment.com
|
* Mike Bierlee, m.bierlee@lostmoment.com
|
||||||
* Copyright: 2014-2016 Mike Bierlee
|
* Copyright: 2014-2017 Mike Bierlee
|
||||||
* License:
|
* License:
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2016 Mike Bierlee
|
* Copyright 2014-2017 Mike Bierlee
|
||||||
* This software is licensed under the terms of the MIT license.
|
* This software is licensed under the terms of the MIT license.
|
||||||
* The full terms of the license can be found in the LICENSE file.
|
* The full terms of the license can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue