Has<M, Env, VALUE> vs. IHas<RT> #1458
-
Hi all! I've been using Language-Ext in production for about 6 months and now about half my team uses it as well. It's been amazing for our code quality so first just a thank you. Now my question - I'm a bit confused on how to use the Has<M, Env, VALUE> and what benefit it provides vs. my IHas
Using it would look like this. Where the runtime env dependencies are defined on the function level rather that the class or record.
Getting a specific dependency when the function requires multiple looks like this
My first thoughts are possibly that Has<> handles disposing in a better way than I'm handling. Would anyone be able to show me a better way of handling this with Has<> or help me understand the functional benefits of the pattern that's already been implemented? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Is that so? public static Eff<RT, RESULT> Execute<RT>(REQUEST request)
where RT :
struct,
IHas<IHttpClientFactory>,
IHas<LogQueue> =>
from rt in runtime<RT>() // gets rt of type RT from Eff<RT, RT>, so the context monad is Eff
from q in rt.Get<LogQueue, RT>() // rt.Get returns RT, but should return Eff<RT> to satisfy "linq expression monad context"
....
It doesnt track and release disposable,
I can remember only this announcement talking about |
Beta Was this translation helpful? Give feedback.
-
The Newsletter sample demos the functionality in real world setting: https://github.com/louthy/language-ext/tree/main/Samples/Newsletter/Newsletter |
Beta Was this translation helpful? Give feedback.
RT
part: it's literally saying thatIHas<T>
is an interface that requires to have implementation a getter of typeT
, what doesRT
(runtime) have to do with anything?Has<M, TRAIT>
andHas<M, ENV TRAIT>
not only get the value, but also wrap it inM
.Is that so?
Get
extension method returns justTDependency
. Your example can't be compiled: