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
<Asidetype="caution"title="Limitation of Direct Method Access">
1204
1204
Direct method access does not work with generic methods.
1205
1205
</Aside>
1206
+
1207
+
### Effect.Service vs Context.Tag
1208
+
1209
+
Both `Effect.Service` and `Context.Tag` are ways to model services in the Effect ecosystem. They serve similar purposes but target different use-cases.
| Best suited for | Application code with a clear runtime implementation | Library code or dynamically-scoped values |
1217
+
| When no sensible default exists | Not ideal; you would still have to invent one | Preferred |
1218
+
1219
+
**Key points**
1220
+
1221
+
-**Less boilerplate:**`Effect.Service` is syntactic sugar over `Context.Tag` plus the accompanying layer and helpers.
1222
+
-**Default required:**
1223
+
A class that extends `Effect.Service` must declare **one** of the built-in constructors (`effect`, `sync`, `succeed`, or `scoped`). This baseline implementation becomes part of `MyService.Default`, so any code that imports the service can run without providing extra layers.
1224
+
That is handy for app-level services where a sensible runtime implementation exists (logging, HTTP clients, real databases, and so on).
1225
+
If your service is inherently contextual (for example, a per-request database handle) or you are writing a library that should not assume an implementation, prefer `Context.Tag`: you publish only the tag and let callers supply the layer that makes sense in their environment.
1226
+
-**The class _is_ the tag:** When you create a class with `extends Effect.Service`, the class constructor itself acts as the tag. You can provide alternate implementations by supplying a value for that class when wiring layers:
0 commit comments