FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dconstructor improvements

Post new topic   Reply to topic     Forum Index -> DMocks
View previous topic :: View next topic  
Author Message

Joined: 03 Feb 2005
Posts: 73
Location: New York

PostPosted: Wed Aug 13, 2008 9:20 am    Post subject: dconstructor improvements Reply with quote

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:

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:

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/
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DMocks All times are GMT - 6 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group