예제 #1
0
def app():
    config = Configurator()
    config.include('pyramid_wiring')

    graph = Graph()
    graph.register_scope(RequestScope, RequestScope())
    class Counter(object):
        def __init__(self):
            self.count = 1
    graph.register_provider('counter', FactoryProvider(Counter, scope=RequestScope))
    config.set_object_graph(graph)

    def count(request, counter=injected('counter')):
        # Increment the counter
        count = counter.count
        counter.count += 1

        # Get the counter from the graph again and make sure it's the same
        assert graph.get('counter') is counter

        return count
    config.add_route('count', '/count')
    config.add_view(count, route_name='count', renderer='string')

    return TestApp(config.make_wsgi_app())
예제 #2
0
파일: wsgi.py 프로젝트: msiedlarek/wiring
def get_application():
    graph = Graph()
    graph.register_scope(RequestScope, RequestScope())
    graph.register_instance(Graph, graph)
    GuestbookModule().add_to(graph)
    graph.validate()
    return graph.get('wsgi.application')