From 20e78b8d93fcab5f62752cae300c0733946ab678 Mon Sep 17 00:00:00 2001 From: Mike Bierlee Date: Tue, 6 May 2014 01:32:22 +0200 Subject: [PATCH] Add registration of concrete classes --- .buildpath | 6 ++++++ .gitignore | 3 +++ .project | 17 +++++++++++++++++ dub.json | 33 +++++++++++++++++++++++++++++++++ source/poodinis/container.d | 19 +++++++++++++++++++ test/poodinis/containertest.d | 15 +++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 .buildpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 dub.json create mode 100644 source/poodinis/container.d create mode 100644 test/poodinis/containertest.d diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..20c7631 --- /dev/null +++ b/.buildpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cf4459 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +poodinis.exe +poodinis.obj +/.settings diff --git a/.project b/.project new file mode 100644 index 0000000..346efe8 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + poodinis + + + + + + org.dsource.ddt.ide.core.DubBuilder + + + + + + org.dsource.ddt.ide.core.nature + + diff --git a/dub.json b/dub.json new file mode 100644 index 0000000..15657d7 --- /dev/null +++ b/dub.json @@ -0,0 +1,33 @@ +{ + "name" : "poodinis", + "description" : "A dependency injection framework.", + "homepage": "http://lostmoment.com", + "authors": ["Lostmoment", "Mike Bierlee"], + "copyright": "Copyright 2014 Lostmoment", + "license": "proprietary", + "configurations": [ + { + "name": "debug-build", + "targetType": "library", + "buildOptions": [ + "debugMode", + "debugInfo" + ] + }, + { + "name": "unittest", + "targetType": "executable", + "buildOptions": [ + "debugMode", + "debugInfo", + "unittests" + ], + "sourcePaths": [ + "test" + ], + "dflags-dmd": [ + "-main" + ] + } + ] +} \ No newline at end of file diff --git a/source/poodinis/container.d b/source/poodinis/container.d new file mode 100644 index 0000000..74d9c07 --- /dev/null +++ b/source/poodinis/container.d @@ -0,0 +1,19 @@ +module poodinis.container; + +struct Registration { + TypeInfo_Class registratedType = null; +} + +class Container { + + private static Registration[] registrations; + + private this() { + } + + public static Registration register(T)() { + Registration newRegistration = { typeid(T) }; + registrations ~= newRegistration; + return newRegistration; + } +} diff --git a/test/poodinis/containertest.d b/test/poodinis/containertest.d new file mode 100644 index 0000000..fa07360 --- /dev/null +++ b/test/poodinis/containertest.d @@ -0,0 +1,15 @@ +import poodinis.container; + +import std.stdio; + +version(unittest) { + class TestClass { + } + + unittest { + // Test register concrete type + auto registration = Container.register!(TestClass)(); + assert(registration.registratedType == typeid(TestClass), "Type of registered type not the same"); + } + +} \ No newline at end of file