-
How to modify AppContext or build global methods? I just started using loco. I read the website and docs help documents in detail. I learned that AppContext can carry most global component objects, but I actually need to register some custom components, such as redis... |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Currently, the Could you share what you're trying to achieve? I'd be happy to help you find the best way to implement it. |
Beta Was this translation helpful? Give feedback.
-
#[allow(clippy::module_name_repetitions)] // 定义与配置文件对应的结构体 #[derive(Serialize, Deserialize, Default, Debug, Clone)] impl Settings { #[async_trait]
} #[derive(Educe)] impl RedisManager {
pub static GLOBAL_STATE: LazyLock = LazyLock::new(|| GlobalState::new()); #[derive(Debug)] Thank you for your reply. I will paste my code for you to analyze. I am not familiar with loco at the beginning. For example, I need to introduce a redis. I understand that redis can be introduced through the middle layer. But my module is not an independent processing module that does not want to go through the middle layer. So I use the init part below for initialization. After initialization, I cannot modify the AppContext. So I can only initialize the module with global static variables and then call it where needed. In this case, does the loco framework provide relevant global storage or global state storage? |
Beta Was this translation helpful? Give feedback.
-
https://loco.rs/docs/the-app/controller/ |
Beta Was this translation helpful? Give feedback.
https://loco.rs/docs/the-app/controller/
I mentioned some issues about state preservation before. Since the loco manual is quite complicated, I missed some parts when I first read it, which led me to build state preservation myself. In fact, the page above clearly shows how to save custom state information.