You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/overview/controllers.md
+10-23Lines changed: 10 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,9 @@
1
1
2
2
The Controller is responsible for handling incoming requests and returning responses to client.
3
3
The purpose of a controller is to receive specific requests for an application and `ApplicationRouter` decides which controller should handle an incoming request.
`CreateDogSerializer`, a pydantic type, so fields(`name`, `age`, `breed`) validations according to defined types and
268
-
specifications is supported out of the box. It's important to note the way we used `CreateDogSerializer` as a type annotation to `payload` parameter in `create` method.
253
+
specifications is supported out of the box.
254
+
255
+
It's important to note the way we used `CreateDogSerializer` as a type annotation to `payload` parameter in `create` method.
269
256
During request Ellar computes the route handler signatures and validates them to the annotated types before executing the handler.
and are set up in a pipeline nature to have a request-response cycle behaviour.
@@ -24,6 +15,7 @@ During request, each `ASGI` Middleware must call the ASGI `app` passed to it dur
24
15
pass
25
16
26
17
```
18
+
27
19
```python
28
20
# ASGI Middleware Interface
29
21
import typing as t
@@ -40,6 +32,7 @@ class EllarASGIMiddlewareStructure:
40
32
```
41
33
42
34
Actions that can be performed by middleware functions:
35
+
43
36
- Execute any code
44
37
- Make changes to request and response objects
45
38
- End the request-response cycle if need be
@@ -96,7 +89,7 @@ class DevelopmentConfig(BaseConfig):
96
89
]
97
90
98
91
```
99
-
This is how to apply any `ASGI` middlewares such as `GZipMiddleware`, `EllarASGIMiddlewareStructure` and others available in `Starlette` library to `Ellar` application
92
+
This is how to apply any `ASGI` middlewares such as `GZipMiddleware`, `EllarASGIMiddlewareStructure` and others available in `Starlette` library.
100
93
101
94
## Starlette Middlewares
102
95
Let's explore other Starlette middlewares and other third party ASGI Middlewares
In our previous `Dogs` module, we can refactor the `DogsController` and move some actions to a service.
34
34
@@ -87,13 +87,14 @@ class DogsController(ControllerBase):
87
87
88
88
...
89
89
```
90
+
90
91
We have defined `DogsRepository` as a dependency to `DogsController` which means Ellar will resolve `DogsRepository` instance when creating `DogsController` instance.
91
92
This was made possible by type definition on `dog_repo` parameter and with the type defined, Ellar knows the provider to look for.
92
93
93
94
!!! info
94
95
Every class dependencies should be defined in the class **constructor**, that way Ellar will resolve all the dependencies needed for an object instantiation.
95
96
96
-
## Provider registration
97
+
## Provider Registration
97
98
To get this working, we need to expose the `DogsRepository` to the `DogsModule` module just like we did for the `DogsController`.
98
99
99
100
```python
@@ -120,7 +121,10 @@ class DogsModule(ModuleBase):
120
121
121
122
## Provider Scopes
122
123
There are different scope which defines different ways a service is instantiated.
123
-
-`transient_scope`: Whenever a transient scoped provider is required, a new instance of the provider is created
124
+
125
+
### `transient_scope`:
126
+
Whenever a transient scoped provider is required, a new instance of the provider is created
127
+
124
128
```python
125
129
from ellar.di import EllarInjector, transient_scope, injectable
-`request_scope`: A request scoped provider is instantiated once during the scope of the request. And its destroyed once the request is complete.
171
+
### `request_scope`:
172
+
A request scoped provider is instantiated once during the scope of the request. And its destroyed once the request is complete.
165
173
It is important to noted that `request_scope` behaves like a `singleton_scope` during HTTPConnection mode and behaves like a `transient_scope` outside a HTTPConnection mode.
174
+
166
175
```python
167
176
from ellar.di import EllarInjector, request_scope, injectable, RequestServiceProvider
0 commit comments