mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-14 19:54:00 +01:00
Shorten name of example to fix compilation issues
This commit is contained in:
parent
9b05aa3af9
commit
0b64013115
6
dub.json
6
dub.json
|
@ -119,11 +119,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "postConstructorPreDestructorExample",
|
"name" : "postConPreDestExample",
|
||||||
"targetType": "executable",
|
"targetType": "executable",
|
||||||
"targetName": "postConstructorPreDestructorExample",
|
"targetName": "postConPreDestExample",
|
||||||
"sourcePaths": [
|
"sourcePaths": [
|
||||||
"example/postconstructorpredestructor"
|
"example/postconpredest"
|
||||||
],
|
],
|
||||||
"importPaths": [
|
"importPaths": [
|
||||||
"source"
|
"source"
|
||||||
|
|
|
@ -1,55 +1,55 @@
|
||||||
/**
|
/**
|
||||||
* Poodinis Dependency Injection Framework
|
* Poodinis Dependency Injection Framework
|
||||||
* Copyright 2014-2023 Mike Bierlee
|
* Copyright 2014-2023 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 public void postConstructor() {
|
@PostConstruct 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 public ADependency dependency; // Dependencies are autowired before the post-constructor is called.
|
@Autowire public ADependency dependency; // Dependencies are autowired before the post-constructor is called.
|
||||||
|
|
||||||
@PostConstruct public void postConstructor() {
|
@PostConstruct 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 public void preDestructor() {
|
@PreDestroy 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).onConstructed((Object obj) {
|
container.register!(ADependency).onConstructed((Object obj) {
|
||||||
writeln("ADependency constructed");
|
writeln("ADependency constructed");
|
||||||
});
|
});
|
||||||
|
|
||||||
container.register!(AClass).onConstructed((Object obj) {
|
container.register!(AClass).onConstructed((Object obj) {
|
||||||
writeln("AClass constructed");
|
writeln("AClass constructed");
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
6
makefile
6
makefile
|
@ -19,7 +19,7 @@ run-examples: run-annotationsExample \
|
||||||
run-arrayCompletionExample \
|
run-arrayCompletionExample \
|
||||||
run-constructorInjectionExample \
|
run-constructorInjectionExample \
|
||||||
run-injectionInitializerExample \
|
run-injectionInitializerExample \
|
||||||
run-postConstructorPreDestructorExample \
|
run-postConPreDestExample \
|
||||||
run-qualifiersExample \
|
run-qualifiersExample \
|
||||||
run-quickstartExample \
|
run-quickstartExample \
|
||||||
run-registerOnResolveExample \
|
run-registerOnResolveExample \
|
||||||
|
@ -40,8 +40,8 @@ run-constructorInjectionExample:
|
||||||
run-injectionInitializerExample:
|
run-injectionInitializerExample:
|
||||||
dub run --build=release --config=injectionInitializerExample
|
dub run --build=release --config=injectionInitializerExample
|
||||||
|
|
||||||
run-postConstructorPreDestructorExample:
|
run-postConPreDestExample:
|
||||||
dub run --build=release --config=postConstructorPreDestructorExample
|
dub run --build=release --config=postConPreDestExample
|
||||||
|
|
||||||
run-qualifiersExample:
|
run-qualifiersExample:
|
||||||
dub run --build=release --config=qualifiersExample
|
dub run --build=release --config=qualifiersExample
|
||||||
|
|
Loading…
Reference in a new issue