owja/ioc

Maybe container has an implicit behavior

Closed this issue · 1 comments

Hi, first of all thanks for pretty good library.

I noticed that container can have an implicit behaviour.

According to api, i can bind service to symbol and save options to the variable.
Later I can start get services from the container by symbol.
But after that I can use options to change type of service by options.toSingletonScope()

After changing service type I will receive only one instance.

I don't know, maybe it is a regular behaviour but it can confuse the developer.

Maybe I'm wrong and this behaviour implies that at the time of binding, the developer may not know what the service should be.

P.S. Sorry for bug label...

it is as intended. to() and toFactory() can marked as singeltons by call .toSingeltonScope() in a chain so they will only created once. That is a one way action. You can store the result of to() and toFactory() in a const but that is not usefull. They are "fire and forget" ;-)

container.bind<ServiceInterface>(symbol).to(Service).inSingletonScope();

or

container.bind<ServiceInterface>(symbol).to(Service);

It could be possible that a later version has also more options.