Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronSima committed Aug 29, 2024
1 parent 92445c5 commit f8bc3f6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ async def home(request, user_service: UserService, logger: LoggingService):

Services can be any class, but Zipline includes a special `Service` class. Classes that inherit from `Service` have the ability to access all other services in their scope.

Classes that inherit from `Service` are expected to have a property `name` attribute, which is used to identify the service in the dependency injection container. Otherwise, they can be referenced by their class name (like with the `@inject` decorator).

```python
from zipline import ZipLine, Service, inject
from zipline import ZipLine, Service

class LoggingService(Service):
def __init__(self):
self.name "logger"
self.name = "logger"

def error(self, message):
print(f"Error! {message}")
Expand Down Expand Up @@ -153,7 +155,7 @@ app = ZipLine()
app.inject([LoggingService, DBService, UserService])

@app.route("/user/:id")
async def get_user(request, user_service: UserService):
async def get_user(request):
user_id = request.path_params.get("id")
return user_service.get_user(user_id)
```
Expand Down

0 comments on commit f8bc3f6

Please sign in to comment.