Access other capsules from a Side Effect? #33
-
Seems that is not possible to access other capsules from within In my resource side effect I would like to use the connection state capsule. This is a logic that would be common to all resources so it would be greate to be able to access directly from the Side Effect. Now, I have to read in the capsule and pass it to the side effect, which is more tedious an repetitive. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
This was an intentional design decision I made back before ReArch was named ReArch (it was called "Unstate" back then for some trivia). The reason: it completely decouples side effects from capsule state, which is important if you want to test them in isolation or port one or the other elsewhere.
Something like this is only an extra line of code and still keeps your side effects and capsules completely decoupled: ResourceManager<FooBar> myResourceCapsule(CapsuleHandle use) {
return use.asResource(
connectionState: use(connectionStateCapsule),
// ...
);
} That, or having your side effect itself manage the connection state itself instead of a different capsule (if that fits in your design). |
Beta Was this translation helpful? Give feedback.
-
I thought maybe you can have two registrar types: coupled and decoupled. But I'm fine to add that single line code :) |
Beta Was this translation helpful? Give feedback.
-
Well, the idea is to have the two concepts completely separate. And unfortunately what you suggested still would break transactions, at least if you allow coupled side effects to read capsules in the txn.
|
Beta Was this translation helpful? Give feedback.
This was an intentional design decision I made back before ReArch was named ReArch (it was called "Unstate" back then for some trivia). The reason: it completely decouples side effects from capsule state, which is important if you want to test them in isolation or port one or the other elsewhere.
Something like this is only an extra line of code and still keeps your side effects and capsules completely decoupled: