# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import collections
import dependency_injector.providers as providers

class C1:
    v1 = 0
    def __init__(self):
        C1.v1 = C1.v1 + 1
        self.v2 = C1.v1
    def __str__(self):
        return '%d/%d' % (self.v2, C1.v1)

class C2:
    v1 = 0
    def __init__(self):
        C2.v1 = C2.v1 + 1
        self.v2 = C2.v1
    def __str__(self):
        return '%d/%d' % (self.v2, C2.v1)

class C:
    def __init__(self, c1a, c1b, c2a, c2b):
        self.c1a = c1a
        self.c1b = c1b
        self.c2a = c2a
        self.c2b = c2b
    def test(self):
        print('Factory   : %s %s' % (self.c1a, self.c1b))
        print('Singleton : %s %s' % (self.c2a, self.c2b))

c1_factory = providers.Factory(C1)
c2_singleton = providers.Singleton(C2)
c_factory = providers.Factory(C,c1a=c1_factory,c1b=c1_factory,c2a=c2_singleton,c2b=c2_singleton)

o = c_factory()
o.test()
