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())
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')