A scope is a special object that controls dependency creation. It decides if new dependency instance should be created, or some cached instance should be returned.

By default, there are two scopes registered in haps: InstanceScope and SingletonScope as haps.INSTANCE_SCOPE and haps.SINGLETON_SCOPE. The haps.INSTANCE_SCOPE is used as a default.

You can register any other scope by calling haps.Container.register_scope(). New scopes should be a subclass of haps.scopes.Scope.

class haps.scopes.Scope[source]

Base scope class. Every custom scope should subclass this.

class haps.scopes.instance.InstanceScope[source]

Dependencies within InstanceScope are created at every injection.

class haps.scopes.singleton.SingletonScope[source]

Dependencies within SingletonScope are created only once in the application context.

class haps.scopes.thread.ThreadScope[source]

Dependencies within ThreadScope are created only once in a thread context.