diff --git a/dub.json b/dub.json index 69eeecc..5acb150 100644 --- a/dub.json +++ b/dub.json @@ -119,11 +119,11 @@ ] }, { - "name" : "postConstructorPreDestructorExample", + "name" : "postConPreDestExample", "targetType": "executable", - "targetName": "postConstructorPreDestructorExample", + "targetName": "postConPreDestExample", "sourcePaths": [ - "example/postconstructorpredestructor" + "example/postconpredest" ], "importPaths": [ "source" diff --git a/example/postconstructorpredestructor/app.d b/example/postconpredest/app.d similarity index 96% rename from example/postconstructorpredestructor/app.d rename to example/postconpredest/app.d index 2e286e6..8c08132 100644 --- a/example/postconstructorpredestructor/app.d +++ b/example/postconpredest/app.d @@ -1,55 +1,55 @@ -/** - * Poodinis Dependency Injection Framework - * Copyright 2014-2023 Mike Bierlee - * This software is licensed under the terms of the MIT license. - * The full terms of the license can be found in the LICENSE file. - */ - -import poodinis; - -import std.stdio; - -class ADependency { - @PostConstruct public void postConstructor() { - writeln("The dependency is created."); - } - - public void callMe() { - writeln("The dependency was called."); - } -} - -class AClass { - @Autowire public ADependency dependency; // Dependencies are autowired before the post-constructor is called. - - @PostConstruct public void postConstructor() { - writeln("The class is created."); - if (dependency !is null) { - writeln("The dependency is autowired."); - } else { - writeln("The dependency was NOT autowired."); - } - } - - @PreDestroy public void preDestructor() { - writeln("The class is no longer registered with the container."); - } -} - -public void main() { - auto container = new shared DependencyContainer(); - container.register!(ADependency).onConstructed((Object obj) { - writeln("ADependency constructed"); - }); - - container.register!(AClass).onConstructed((Object obj) { - writeln("AClass constructed"); - }); - - auto instance = container.resolve!AClass; // Will cause the post constructor 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, - // it will not be collected by the garbage collector either. - instance.dependency.callMe(); -} +/** + * Poodinis Dependency Injection Framework + * Copyright 2014-2023 Mike Bierlee + * This software is licensed under the terms of the MIT license. + * The full terms of the license can be found in the LICENSE file. + */ + +import poodinis; + +import std.stdio; + +class ADependency { + @PostConstruct public void postConstructor() { + writeln("The dependency is created."); + } + + public void callMe() { + writeln("The dependency was called."); + } +} + +class AClass { + @Autowire public ADependency dependency; // Dependencies are autowired before the post-constructor is called. + + @PostConstruct public void postConstructor() { + writeln("The class is created."); + if (dependency !is null) { + writeln("The dependency is autowired."); + } else { + writeln("The dependency was NOT autowired."); + } + } + + @PreDestroy public void preDestructor() { + writeln("The class is no longer registered with the container."); + } +} + +public void main() { + auto container = new shared DependencyContainer(); + container.register!(ADependency).onConstructed((Object obj) { + writeln("ADependency constructed"); + }); + + container.register!(AClass).onConstructed((Object obj) { + writeln("AClass constructed"); + }); + + auto instance = container.resolve!AClass; // Will cause the post constructor 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, + // it will not be collected by the garbage collector either. + instance.dependency.callMe(); +} diff --git a/makefile b/makefile index 9463872..80c42d7 100644 --- a/makefile +++ b/makefile @@ -19,7 +19,7 @@ run-examples: run-annotationsExample \ run-arrayCompletionExample \ run-constructorInjectionExample \ run-injectionInitializerExample \ - run-postConstructorPreDestructorExample \ + run-postConPreDestExample \ run-qualifiersExample \ run-quickstartExample \ run-registerOnResolveExample \ @@ -40,8 +40,8 @@ run-constructorInjectionExample: run-injectionInitializerExample: dub run --build=release --config=injectionInitializerExample -run-postConstructorPreDestructorExample: - dub run --build=release --config=postConstructorPreDestructorExample +run-postConPreDestExample: + dub run --build=release --config=postConPreDestExample run-qualifiersExample: dub run --build=release --config=qualifiersExample