Skip to content

Commit 876b3cb

Browse files
authored
Merge pull request #45 from eadwinCode/doc_image_update
Documentation Image Update
2 parents 42f8a87 + d2e4ea4 commit 876b3cb

File tree

7 files changed

+35
-68
lines changed

7 files changed

+35
-68
lines changed

docs/img/ModuleDescription.png

89.9 KB
Loading

docs/img/controller_description.png

49.2 KB
Loading

docs/img/middleware.png

51.1 KB
Loading

docs/overview/controllers.md

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11

22
The Controller is responsible for handling incoming requests and returning responses to client.
33
The purpose of a controller is to receive specific requests for an application and `ApplicationRouter` decides which controller should handle an incoming request.
4-
```
5-
┌───────────────────┐
6-
┌─────►│ controller │
7-
│ └───────────────────┘
8-
9-
10-
11-
12-
13-
┌─────────────────────┐ ┌────────────────────┐ │
14-
│ client requests ├─◄──────────────►│ Application Router ├─◄──┤
15-
└─────────────────────┘ └────────────────────┘ │
16-
17-
18-
19-
│ ┌────────────────────┐
20-
└─────►│ controller │
21-
└────────────────────┘
22-
```
4+
5+
![controller description image](../img/controller_description.png)
6+
237
Controllers can also be seen as a router which has many routes registered in it.
248

259
### Creating a Controller
@@ -74,7 +58,7 @@ For example, a path prefix of `/users` combined with the decorator `@get('/profi
7458
`GET /users/profile`.
7559

7660

77-
#### Overview of HTTP function decorator parameters:
61+
### Overview of HTTP function decorator parameters:
7862

7963
`@get(path: str, name: str, include_in_schema: bool, response: t.Union[t.Dict[int, t.Type], t.List[t.Tuple[int, t.Type]], t.Type])`
8064

@@ -88,8 +72,9 @@ Ellar will always serialize all HTTP handler functions returned data as `json` u
8872
For the above example, `get_all` returned a string. This will be serialized to json with a `status code` 200.
8973

9074

91-
## Request object
92-
There are different ways handlers can access client request details
75+
## Request Object
76+
There are different ways handlers can access client request details:
77+
9378
- Annotation (`parameter_name:Request`)
9479
Ellar will resolve any parameter annotated as `Request` in request handler signature as `Request` object.
9580
```python
@@ -265,7 +250,9 @@ async def create(self, payload: CreateDogSerializer = Body()):
265250
```
266251

267252
`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.
269256
During request Ellar computes the route handler signatures and validates them to the annotated types before executing the handler.
270257

271258
![CreateDogSchema](../img/create-dog-schema.png)

docs/overview/middleware.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
Middlewares are functions that are called during request before hitting a specific route handler.
22
Middleware functions can modify **request** and **response** objects during `http` or `websocket` connection.
33

4-
```
5-
┌────────────────────────────┐
6-
┌──────────────────────┐ request │ │ request ┌────────────────────────────┐
7-
│ ├───────────────────────►│ CORSMiddleware ├──────────────────► │ │
8-
│ Client Request │ │ │ │ Route Handler │
9-
│ │◄────────────────────── │ TrustedHostMiddleware │◄────────────────── │ │
10-
└──────────────────────┘ response │ │ response └────────────────────────────┘
11-
│ .... │
12-
└────────────────────────────┘
13-
```
4+
![middleware description image](../img/middleware.png)
145

156
Ellar Middlewares follows [`Starlette ASGI Middleware`](https://www.starlette.io/middleware/) pattern
167
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
2415
pass
2516

2617
```
18+
2719
```python
2820
# ASGI Middleware Interface
2921
import typing as t
@@ -40,6 +32,7 @@ class EllarASGIMiddlewareStructure:
4032
```
4133

4234
Actions that can be performed by middleware functions:
35+
4336
- Execute any code
4437
- Make changes to request and response objects
4538
- End the request-response cycle if need be
@@ -96,7 +89,7 @@ class DevelopmentConfig(BaseConfig):
9689
]
9790

9891
```
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.
10093

10194
## Starlette Middlewares
10295
Let's explore other Starlette middlewares and other third party ASGI Middlewares

docs/overview/modules.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
11
A module is a class annotated with a `@Module()` decorator.
22
The `@Module()` decorator provides **metadata** that **Ellar** makes use of to organize the application structure.
3-
```
4-
┌──────────────────────────────┐
5-
│ │
6-
┌──────────────────► │ ApplicationModule │ ◄─────────────────────────┐
7-
│ │ │ │
8-
│ └──────────────────────────────┘ │
9-
│ ▲ │
10-
│ │ │
11-
│ │ │
12-
│ │ │
13-
│ │ │
14-
┌─────────────┴─────────────┐ ┌──────────┴─────────────────┐ ┌──────────────┴───────────────┐
15-
│ │ │ │ │ │
16-
│ BooksModule │ │ StoreModule │ ┌───►│ OrderModule │ ◄──────┐
17-
│ │ │ │ │ │ │ │
18-
└───────────────────────────┘ └────────────────────────────┘ │ └──────────────────────────────┘ │
19-
▲ │ │
20-
│ │ │
21-
│ │ │
22-
│ │ │
23-
│ │ │
24-
┌──────────────┴────────────┐ ┌────────────┴────────────────┐ ┌─────────────────────┴────────┐
25-
│ │ │ │ │ │
26-
│ SubscriptionModule │ │ AnyFeatureModule1 │ │ AnyFeatureModule2 │
27-
│ │ │ │ │ │
28-
└───────────────────────────┘ └─────────────────────────────┘ └──────────────────────────────┘
29-
```
3+
4+
![middleware description image](../img/ModuleDescription.png)
5+
306
The `ApplicationModule` is the entry point for Ellar to build your application graph -
317
the internal data structure used to resolve module and provider relationships and dependencies.
328
The best way to organize your components is to build your projects as `Modules`.
@@ -95,6 +71,7 @@ class BookModule(ModuleBase):
9571
| `static_folder` | defines the static folder for this module |
9672
| `template_folder` | defines the template folder for this module |
9773

74+
9875
## `Additional Module Configurations`
9976
### `Module Events`
10077
Every registered Module receives two event calls during its instantiation and when application is ready.

docs/overview/providers.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class UserRepository:
2828

2929
class UserController(ControllerBase):
3030
def __init__(self, user_repo: UserRepository) -> None:
31-
self.userRepo = user_repo
31+
self.user_repo = user_repo
3232
```
3333
In our previous `Dogs` module, we can refactor the `DogsController` and move some actions to a service.
3434

@@ -87,13 +87,14 @@ class DogsController(ControllerBase):
8787

8888
...
8989
```
90+
9091
We have defined `DogsRepository` as a dependency to `DogsController` which means Ellar will resolve `DogsRepository` instance when creating `DogsController` instance.
9192
This was made possible by type definition on `dog_repo` parameter and with the type defined, Ellar knows the provider to look for.
9293

9394
!!! info
9495
Every class dependencies should be defined in the class **constructor**, that way Ellar will resolve all the dependencies needed for an object instantiation.
9596

96-
## Provider registration
97+
## Provider Registration
9798
To get this working, we need to expose the `DogsRepository` to the `DogsModule` module just like we did for the `DogsController`.
9899

99100
```python
@@ -120,7 +121,10 @@ class DogsModule(ModuleBase):
120121

121122
## Provider Scopes
122123
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+
124128
```python
125129
from ellar.di import EllarInjector, transient_scope, injectable
126130

@@ -140,7 +144,10 @@ a_transient_instance_2 = injector.get(ATransientClass)
140144

141145
assert a_transient_instance_2 != a_transient_instance_1 # True
142146
```
143-
- `singleton_scope`: A singleton scoped provider is created once throughout the lifespan of the Container instance. For example
147+
148+
### `singleton_scope`:
149+
A singleton scoped provider is created once throughout the lifespan of the Container instance. For example
150+
144151
```python
145152
from ellar.di import EllarInjector, singleton_scope, injectable
146153

@@ -161,8 +168,10 @@ a_singleton_instance_2 = injector.get(ASingletonClass)
161168
assert a_singleton_instance_2 == a_singleton_instance_1 # True
162169
```
163170

164-
- `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.
165173
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+
166175
```python
167176
from ellar.di import EllarInjector, request_scope, injectable, RequestServiceProvider
168177

@@ -190,7 +199,8 @@ assert request_instance_2 != request_instance_1
190199

191200
## Provider Configurations
192201
There are two ways we can configure providers that are required in EllarInjector IoC.
193-
- `ProviderConfig`:
202+
203+
### `ProviderConfig`:
194204
With `ProviderConfig` we can register `base_type` against a `concrete_type` or register a `base_type` against a value type.
195205

196206
For example:
@@ -244,7 +254,7 @@ assert a_module_instance.ifoo_b == a_foo_instance
244254
In above example, we used `ProviderConfig` as a value type as in the case of `IFooB` type and
245255
as a concrete type as in the case of `IFoo` type.
246256

247-
- `register_providers`:
257+
### `register_providers`:
248258
We can also achieve the same by overriding `register_providers` in any Module class.
249259

250260
For example:

0 commit comments

Comments
 (0)