public AbstractBinding toProvider(Type providerType) { AbstractBinding abstractBinding = withDecoration(new ProviderAbstractBinding(typeDefinition, new TypeDefinition(providerType))); binder.addBinding(abstractBinding); return(abstractBinding); }
public AbstractBinding to(Type dependency) { AbstractBinding abstractBinding = withDecoration(new TypeAbstractBinding(typeDefinition, new TypeDefinition(dependency))); binder.addBinding(abstractBinding); return(abstractBinding); }
public AbstractBinding toInstance(object instance) { //At first it seems silly to have a singleton decorator around an instance, but it affects our rules for overriding in ChildInjectors, so keep it AbstractBinding abstractBinding = withDecoration(new InstanceAbstractBinding(typeDefinition, instance)); binder.addBinding(abstractBinding); return(abstractBinding); }
AbstractBinding withDecoration(AbstractBinding abstractBinding) { if (scope == Scope.Context) { abstractBinding = new ContextDecorator(abstractBinding); } else if (scope == Scope.Singleton) { abstractBinding = new SingletonDecorator(abstractBinding); } return(abstractBinding); }
public BindingFactory bind(Type type) { var typeDefinition = new TypeDefinition(type); AbstractBinding existingBinding = getBinding(typeDefinition); //Do we already have a binding for this type? if (existingBinding != null) { /** Having a binding is actually not a problem, in most cases we accept that the last configured binding is the appropriate one * However, in the case of a Singleton, this could actually wreak some havoc on the system, especially if this is a child injector situation and we now * have multiple instances of a singleton..... SO, we throw an error if someone attempts to reconfigure a singleton. Incidentally, if you want your * parent and child injectors to be able to override 'global-ish' singlteon like objects, use the Context scope or make your own object and use the * instance binding. **/ if (existingBinding.getScope() == Scope.Singleton) { throw new JsError("Overriding bindings for Singleton Scoped injections is not allowed."); } } var factory = new BindingFactory(this, typeDefinition); return(factory); }
AbstractBinding withDecoration( AbstractBinding abstractBinding ) { if (scope == Scope.Context) { abstractBinding = new ContextDecorator(abstractBinding); } else if (scope == Scope.Singleton ) { abstractBinding = new SingletonDecorator(abstractBinding); } return abstractBinding; }
public void addBinding(AbstractBinding abstractBinding) { hashMap[abstractBinding.getTypeName()] = abstractBinding; }