You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there,
I have a question about this piece of code:
This is how my factory looks like. As you can see I'm binding/unbinding some classes inside this factory method.
exportfunctionSceneFactory(context: interfaces.Context){return(key: string,scene: any)=>{// Unbind the scene if it existsif(context.container.isBound(key)){context.container.unbind(key);}// Bind the new scene classcontext.container.bind<IScene>(key).to(scene);returncontext.container.get<IScene>(key);};}
A better approach is to create a child container in the factory. This way, the original container isn't modified:
exportfunctionSceneFactory(context: interfaces.Context){return(key: string,scene: any)=>{constchildContainer=context.container.createChild();// Bind the new scene class (since this is bound in the child container, it will override any existing binds)childContainer.bind<IScene>(key).to(scene);returnchildContainer.get<IScene>(key);};}
Is it good to create multiple child containers for other manager classes?
Let's say that If I have Sound Manager (which has SoundFactory), should I create a new child container?
Hello there,
I have a question about this piece of code:
This is how my factory looks like. As you can see I'm binding/unbinding some classes inside this factory method.
I'm using it like that:
So, the question is:
Is it okay to bind/unbind classes in a factory method? Is it a good approach to do that?
The text was updated successfully, but these errors were encountered: