Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created July 1, 2012 03:47
Show Gist options
  • Save tototoshi/3026732 to your computer and use it in GitHub Desktop.
Save tototoshi/3026732 to your computer and use it in GitHub Desktop.
spring-python
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.org/springpython/schema/objects/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/springpython/schema/objects/1.1
http://springpython.webfactional.com/schema/context/spring-python-context-1.1.xsd">
<object id="greeting" class="example1.GoodBye" />
</objects>
objects:
- object: greeting
class: example2.Hello
scope: prototype
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from springpython.context import ApplicationContext
from springpython.config import XMLConfig
class Hello:
def greet(self):
print "Hello"
class GoodBye:
def greet(self):
print "GoodBye"
if __name__ == '__main__':
container = ApplicationContext(XMLConfig("app-context.xml"))
greeting = container.get_object("greeting")
greeting.greet()
# $ ./example1.py
# GoodBye
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from springpython.context import ApplicationContext
from springpython.config import YamlConfig
class Hello:
def greet(self):
print "Hello"
class GoodBye:
def greet(self):
print "GoodBye"
if __name__ == '__main__':
container = ApplicationContext(YamlConfig("app-context.yaml"))
greeting = container.get_object("greeting")
greeting.greet()
# $ ./example2.py
# Hello
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from springpython.context import ApplicationContext
from springpython.config import PythonConfig, scope, Object
class GreetApplicationContext(PythonConfig):
@Object(scope.PROTOTYPE)
def greeting(self):
return Hello()
class Hello:
def greet(self):
print "Hello"
class GoodBye:
def greet(self):
print "GoodBye"
if __name__ == '__main__':
container = ApplicationContext(GreetApplicationContext())
greeting = container.get_object("greeting")
greeting.greet()
# $ ./example3.py
# Hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment