Add registration of concrete classes

This commit is contained in:
Mike Bierlee 2014-05-06 01:32:22 +02:00
commit 20e78b8d93
6 changed files with 93 additions and 0 deletions

6
.buildpath Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="con" path="org.eclipse.dltk.launching.INTERPRETER_CONTAINER"/>
<buildpathentry kind="con" path="org.dsource.ddt.ide.core.DubContainer"/>
<buildpathentry kind="src" path="source"/>
</buildpath>

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
poodinis.exe
poodinis.obj
/.settings

17
.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>poodinis</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.dsource.ddt.ide.core.DubBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.dsource.ddt.ide.core.nature</nature>
</natures>
</projectDescription>

33
dub.json Normal file
View file

@ -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"
]
}
]
}

View file

@ -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;
}
}

View file

@ -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");
}
}