thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

Each type is auto bound #22

Open bssergy opened 6 years ago

bssergy commented 6 years ago

Currently, if we didn't bind type, it will be bound on get method:

    static get(source: Function) {
        const config: ConfigImpl = <ConfigImpl>IoCContainer.bind(source);
        if (!config.iocprovider) {
            config.to(<FunctionConstructor>config.source);
        }
        return config.getInstance();
    }

But I want to return undefined if I forgot to bind a class (i.e. for unit tests). Could you fix to don't use bind() method in get() method()? I don't want to bind if I need just get type.

thiagobustamante commented 6 years ago

I think we can create some configuration option to the Container to enable this behavior you want. I can not just change it because it would break a lot of code. In addition, auto bind is a nice feature that can reduce the configuration in many cases.