Plugins, Property Injections and Reflection

Dennis Kempin dennis at xardias.net
Wed Feb 7 03:00:22 PST 2007


Hi,

i had been using Java and liked the modern Container concepts (Just like
picocontainer.codehaus.org). I was wondering if something similar is
possible with D.
The following things are needed and i dont know exactly if this is possible
with D:
- Dynamically loading D binaries (Using .dll, .so files). I found the DDL
Project at dsource which should help on this. But at the moment it is not
available for D 1.0
- Java-like reflection for property injection: Well i know how to access
class fields using indices, but it would be be very helpful to have an
name->index mapping which can be used to set fields depending on their
name.

In the end it should be possible to place plugin files into a folder and
inject properties into classes loaded from these plugins. Just like this:

configuration file:
TestClass.testProperty=Hello

D interface source file:
interface TestInterface
{
        public void test();     
}

D implementation source file:
class TestClass: TestInterface // implement the Interface
{
        public char[] testProperty;
        public void test(){ writefln(testProperty); }
}

D usage:
// create a TestClass instance and inject the testProperty=Hello value
TestInterface test = Factory.loadFromPlugin(..); 
test.test(); // should now print "Hello"

The interface is known at compile time of the host application, but the
implementation should be replaceable at start time.

I hope you understand what i plan to do.
regards
Dennis



More information about the Digitalmars-d mailing list