mirror of
https://github.com/mbierlee/poodinis.git
synced 2024-11-15 04:04:01 +01:00
Add registration of concrete classes
This commit is contained in:
commit
20e78b8d93
6
.buildpath
Normal file
6
.buildpath
Normal 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
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
poodinis.exe
|
||||
poodinis.obj
|
||||
/.settings
|
17
.project
Normal file
17
.project
Normal 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
33
dub.json
Normal 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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
19
source/poodinis/container.d
Normal file
19
source/poodinis/container.d
Normal 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;
|
||||
}
|
||||
}
|
15
test/poodinis/containertest.d
Normal file
15
test/poodinis/containertest.d
Normal 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");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue