def bind(self, _class, **kwargs): key = Key(interface=_class, annotation=kwargs.get('annotated_with')) binding = Binding() binding.key = key binding.scope = kwargs.get('in_scope', scopes.NO_SCOPE) if key in self._binding_map: self.add_error('baseclass %r already bound' % _class) if 'to' in kwargs: if not isinstance(kwargs['to'], type): self.add_error('to requires a new-style class') binding.provider = providers.create_simple_provider(kwargs['to']) elif 'to_provider' in kwargs: #TODO: add some validation provider = kwargs['to_provider'] binding.provider = provider elif 'to_instance' in kwargs: if not isinstance(kwargs['to_instance'], object): self.add_error('to_instance requires an instance of a ' 'new-style class') provider = kwargs['to_instance'] binding.provider = providers.create_instance_provider(provider) self._binding_map[key] = binding
def bind(self, _class, **kwargs): key = Key(interface=_class, annotation=kwargs.get('annotated_with')) binding = Binding() binding.key = key binding.scope = kwargs.get('in_scope', scopes.NO_SCOPE) if key in self._binding_map: self.add_error('baseclass %r already bound' % _class) if 'to' in kwargs: if not isinstance(kwargs['to'], type): self.add_error('to requires a new-style class') binding.provider = providers.create_simple_provider(kwargs['to']) elif 'to_provider' in kwargs: #TODO: add some validation provider = kwargs['to_provider'] binding.provider = provider elif 'to_instance' in kwargs: if not isinstance(kwargs['to_instance'], object): self.add_error('to_instance requires an instance of a ' 'new-style class') provider = kwargs['to_instance'] binding.provider = providers.create_instance_provider(provider) self._binding_map[key] = binding
def _dsl_to_provider(self, to, to_provider, to_instance): if to: #TODO: add some validation return providers.create_simple_provider(to) elif to_provider: #TODO: add some validation return to_provider elif to_instance: #TODO: add some validation return providers.create_instance_provider(to_instance) else: raise MultiBindingError('incorrect arguments to %s.add_binding' % self.__class__.__name__)
def bind(self, _class, **kwargs): key = Key(interface=_class, annotation=kwargs.get('annotated_with')) binding = Binding() binding.key = key scope = kwargs.get('in_scope') if scope is not None: if not self._scope_cache.has_key(scope): raise errors.BindingError("'scope' has not been bound to this Binder via bind_scope") scope = self._scope_cache[scope] else: scope = self._scope_cache[scopes.NO_SCOPE] binding.scope = scope if key in self._binding_map: raise errors.BindingError('baseclass %r already bound' % _class) if 'to' in kwargs: if not isinstance(kwargs['to'], type): raise errors.BindingError("'to' requires a new-style class") binding.provider = providers.create_simple_provider(kwargs['to']) elif 'to_provider' in kwargs: #TODO: add some validation provider = kwargs['to_provider'] binding.provider = provider elif 'to_instance' in kwargs: if not isinstance(kwargs['to_instance'], object): raise errors.BindingError( "'to_instance' requires an instance of a new-style class") provider = kwargs['to_instance'] binding.provider = providers.create_instance_provider(provider) self._binding_map[key] = binding
def configure(self, binder): dictbinder = DictBinder(binder, ISnack) dictbinder.add_binding('lays', to=Lays) provider = providers.create_simple_provider(Tostitos) dictbinder.add_binding('tostitos', to_provider=provider) dictbinder.add_binding('ruffles', to_instance=Ruffles())
def configure(self, binder): dictbinder = DictBinder(binder, ISnack) dictbinder.add_binding('twix', to=Twix) provider = providers.create_simple_provider(Snickers) dictbinder.add_binding('snickers', to_provider=provider) dictbinder.add_binding('skittles', to_instance=Skittles())
def configure(self, binder): listbinder = ListBinder(binder, ISnack) listbinder.add_binding(to=Lays) provider = providers.create_simple_provider(Tostitos) listbinder.add_binding(to_provider=provider) listbinder.add_binding(to_instance=Ruffles())
def configure(self, binder): listbinder = ListBinder(binder, ISnack) listbinder.add_binding(to=Twix) provider = providers.create_simple_provider(Snickers) listbinder.add_binding(to_provider=provider) listbinder.add_binding(to_instance=Skittles())
def configure(self, binder): dictbinder = DictBinder(binder, ISnack, annotated_with='FritoLaySnackMachine') provider = providers.create_simple_provider(Tostitos) dictbinder.add_binding('Tostitos', to_provider=provider, in_scope=scopes.SINGLETON) dictbinder.add_binding('Ruffles', to_instance=Ruffles(), in_scope=scopes.SINGLETON)
def configure(self, binder): listbinder = DictBinder(binder, ISnack) listbinder.add_binding('Lays', to=Lays, in_scope=scopes.SINGLETON) provider = providers.create_simple_provider(Tostitos) listbinder.add_binding('Tostitos', to_provider=provider, in_scope=scopes.SINGLETON) listbinder.add_binding('Ruffles', to_instance=Ruffles(), in_scope=scopes.SINGLETON)
def configure(self, binder): dictbinder = DictBinder(binder, ISnack) dictbinder.add_binding('lays', to=Lays) provider = providers.create_simple_provider(Tostitos) dictbinder.add_binding('tostitos', to_provider=provider) dictbinder.add_binding('ruffles', to_instance=Ruffles())
def configure(self, binder): dictbinder = DictBinder(binder, ISnack) dictbinder.add_binding('twix', to=Twix) provider = providers.create_simple_provider(Snickers) dictbinder.add_binding('snickers', to_provider=provider) dictbinder.add_binding('skittles', to_instance=Skittles())
def configure(self, binder): listbinder = ListBinder(binder, ISnack) listbinder.add_binding(to=Lays) provider = providers.create_simple_provider(Tostitos) listbinder.add_binding(to_provider=provider) listbinder.add_binding(to_instance=Ruffles())
def configure(self, binder): listbinder = ListBinder(binder, ISnack) listbinder.add_binding(to=Twix) provider = providers.create_simple_provider(Snickers) listbinder.add_binding(to_provider=provider) listbinder.add_binding(to_instance=Skittles())