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/custom_decorators.md
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,8 +45,9 @@ The **Inject[Type]** annotation is used to inject a service registered in Ellar
45
45
46
46
For example:
47
47
```python
48
+
from ellar.app import App
48
49
from ellar.common import ModuleRouter, Inject
49
-
from ellar.core importApp, Config
50
+
from ellar.core import Config
50
51
from sqlalchemy.ext.asyncio import AsyncSession
51
52
52
53
@@ -172,7 +173,7 @@ def get_requests_case_2(
172
173
## **Custom Parameter Decorators**
173
174
You can create your own route parameter decorators whenever necessary. You simply need to follow a contract, `NonParameterResolver`, and override the resolve function.
174
175
175
-
The `NonParameterResolver` has two attribute, `type_annotation` and `parameter_name`, that are provided automatically when computing route function parameter dependencies.
176
+
The `NonParameterResolver` has two attributes, `type_annotation` and `parameter_name`, that are provided automatically when computing route function parameter dependencies.
176
177
The `type_annotation` and `parameter_name` are determined from the parameter declaration like so - `def route_function(parameter_name:type_annotation = NonParameterResolver())`.
177
178
178
179
All `NonParameterResolver` receives current `IExecutionContext` during route function execution, and it must return a tuple of dict object of the resulting resolve data with `parameter_name` and list of errors if any.
@@ -445,11 +446,13 @@ See [Ellar-CLI Custom Commands](../cli/introduction.md){target="_blank"}
445
446
446
447
-`@exception_handler`: This decorator is used to register a function as an exception handler. This function will be called when an unhandled exception occurs during a request. It should take the exception instance as its only argument and return a response object.
447
448
448
-
-`@middleware`: This decorator is used to register a function as a middleware. Middlewares are called for each incoming request and can be used to modify the request or response, or perform any other actions before or after the request is handled.
449
+
-`@middleware`: This decorator is used to register a function as middleware. Middlewares are called for each incoming request and can be used to modify the request or response, or perform any other actions before or after the request is handled.
449
450
450
-
-`@template_filter`: This decorator is used to register a function as a Jinja2 template filter. The function should take one or more arguments and return a modified value.
451
+
-`@template_filter`: This decorator is used to register a function as a Jinja2 template filter.
451
452
452
-
-`@template_global`: This decorator is used to register a function as a global variable available in all Jinja2 templates. The function can be called without any arguments and should return a value.
453
+
-`@template_global`: This decorator is used to register a function as a global variable available in all Jinja2 templates.
453
454
455
+
-`@template_context`: This decorator is used to register a function as a global template context for dynamic template context processing.
456
+
454
457
These decorators can be used to define functions that will be executed at specific points in the application's lifecycle.
455
458
They provide a way to separate and organize the different parts of an application. See [Module Additional Configuration](modules.md#additional-module-configurations){target="_blank"} for examples on how these decorator functions are used.
Copy file name to clipboardExpand all lines: docs/overview/guards.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
1
# **Guards**
2
2
3
3
A **Guard** in Ellar is a way to add **authentication** and **authorization** checks to your application.
4
-
It acts as a middleware and runs before executing the route handler. If the guard returns **false**, the request is rejected and the execution is stopped.
4
+
It acts as middleware and runs before executing the route handler.
5
+
If the guard returns **false**, the request is rejected and the execution is stopped.
5
6
6
7
**Guards** can be used to check for specific roles, permissions, or any other arbitrary condition.
7
8
They can be easily applied to individual routes or groups of routes using `@guard` decorator.
Copy file name to clipboardExpand all lines: docs/overview/interceptors.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,4 +145,6 @@ class InterceptCustomException(EllarInterceptor):
145
145
return {"message": str(cex)}
146
146
```
147
147
148
-
In the above code, the `InterceptCustomException` interceptor catches any `CustomException` raised during the execution of the request/response cycle. It then modifies the response object to set the status code to 400 and returns a JSON response containing the exception message. This allows for custom handling of exceptions within the interceptor before they are propagated to the system's exception handlers.
148
+
In the above code, the `InterceptCustomException` interceptor catches any `CustomException` raised during the execution of the request/response cycle.
149
+
It then modifies the response object to set the status code to 400 and returns a JSON response containing the exception message.
150
+
This allows for custom handling of exceptions within the interceptor before they are propagated to the system's exception handlers.
Copy file name to clipboardExpand all lines: docs/overview/modules.md
+14-12Lines changed: 14 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,7 @@ from ellar.core import ModuleBase
48
48
modules=[],
49
49
providers=[],
50
50
controllers=[],
51
+
exports=[],
51
52
routers=[],
52
53
commands=[],
53
54
base_directory=None,
@@ -63,6 +64,7 @@ class BookModule(ModuleBase):
63
64
|`name`| The name of the module. It's relevant for identification purposes. |
64
65
|`modules`| A list of dependencies required by this module. |
65
66
|`providers`| Providers to be instantiated by the Ellar injector, possibly shared across this module. |
67
+
|`exports`| List of services accessible at application scope level. |
66
68
|`controllers`| Controllers defined in this module that need instantiation. |
67
69
|`routers`| ModuleRouters defined in this module. |
68
70
|`commands`| Functions decorated with `EllarTyper` or `command` that serve as commands. |
@@ -76,19 +78,19 @@ class BookModule(ModuleBase):
76
78
The Ellar framework offers additional module configurations to handle various aspects of the application lifecycle and behavior.
77
79
78
80
### Module Events
79
-
Modules can define `before_init` class method to configure additional initialization parameters before instantiation. This method receives the current application config as a parameter, allowing for further customization.
81
+
Modules can define `post_build` class method
82
+
can be used to define additional `Module` properties after `Module` has built successfully.
80
83
81
84
```python linenums="1"
82
-
import typing
83
85
from ellar.common import Module
84
-
from ellar.core import ModuleBase, Config
86
+
from ellar.core.modulesimport ModuleBase, ModuleRefBase
0 commit comments