-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from piraz/develop
Implemented sessioned decorator for services.
- Loading branch information
Showing
6 changed files
with
305 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Services | ||
======== | ||
|
||
The way firenado organizes the logic to be executed in several parts of an | ||
application is defining services. | ||
|
||
Those services can be injected with the decorator | ||
``firenado.service.served_by``. This decorator will add an instance of a | ||
service to a method of any data connected object. Examples of data connected | ||
classes are ``firenado.tornadoweb.TornadoHandler`` and any descendent of | ||
``firenado.service.FirenadoService``. | ||
|
||
Creating a service and decorating a handler: | ||
|
||
.. code-block::python | ||
from firenado import service, tornadoweb | ||
# Importing a package with some services | ||
import another_service_package | ||
class MyService(service.FirenadoService): | ||
def do_something(self): | ||
# Self consumer will be the handler where this service was | ||
# called from. | ||
self.consumer.write("Something was done") | ||
class MyHandlerBeingServed(tornadoweb.TornadoHandler): | ||
# A good way to keep the reference is keeping the type hint | ||
my_service: MyService | ||
service_from_another_package: another_service_package.AnotherService | ||
@service.served_by(MyService) | ||
# you can also set the attribute/property name to be used | ||
@service.served_by(another_service_package.AnotherService, | ||
attribute_name="service_from_another_package" | ||
) | ||
def get(self): | ||
# The anotation service.served_by added self.my_service | ||
# here. The attribute/property name will be converted from the | ||
# cammel cased class to dashed separated. | ||
self.my_service.do_something() | ||
self.service_from_another_package.do_another_thing() | ||
You can also add services to another services using the decorator: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.