dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Wed Aug 13, 2008 9:20 am Post subject: dconstructor improvements |
|
|
Since the last release, dconstructor has undergone a number of improvements:
- Default singleton
You can specify that dconstructor treat types as singleton by default (this is the default behavior) or that it should create new instances each time. Just call builder().defaultSingleton(true) to have singletons by default, or builder().defaultSingleton(false) to have instance classes by default.
- Autobuild versus registration
By default, dconstructor will throw an exception if you attempt to build a type that was not registered. If you want dconstructor to attempt to build anything it possibly can, even if it wasn't registered, you can set builder().autobuild(true).
- Interceptor support
You can add interceptors to a builder. There's an example of this in trunk/dconstructor/examples/interception.d.
- Configuration
Instead of calling Builder.bind a lot, you can now use a predefined template:
Code: |
interface IService {}
class ServiceImpl
{
mixin (Implements!(IService));
}
|
To support this, dconstructor.build.builder was changed from a Builder instance to a function that returns a Builder!(). Therefore, the recommended way of configuring dconstructor, if the defaults do not work for you, is:
Code: |
module mypackage.builder;
private Builder!(MyInterceptor1, MyInterceptor2) _builder;
public typeof(_builder) builder()
{
if (_builder is null)
{
_builder = new typeof(_builder)();
// any other settings here
}
return _builder;
}
|
Then have your other modules import mypackage.builder rather than dconstructor.builder. There's an example of this in trunk/dconstructor/examples/interception.d, though that is a single module.
Get it while it's hot: http://svn.dsource.org/projects/dmocks/tags/dconstructor.r97/ |
|