Tighter type constraint
Hello.
Let's say I have the following
and then maybe I have concrete like:
I can do the following now for type-safety, i.e., that to get
Order
you must provide an OrderId
and you can't mistakenly provide the wrong strongly typed ID:
However, this makes for quite a verbose API, is it possible somehow to constrain this so it is possible that LoadAggregate<Order>(orderId)
is only valid if orderId
is an OrderId
and not say ProductId
?5 Replies
Not today. What you're talking about here is associated types, which is proposed, but not yet fleshed out and implemented
Oh, that's a bummer!
Do you have any suggestions on some way to get relatively close to it?
No, what you have there is as close as you can get
Or let me rephrase, any way to possibly improve the verbosity of the API
Ok, I appreciate your help 🙂 Thank you a lot
This might be really dumb, but would a "solution" be to... source generate every instance of
Aggregate<TId>
?You certainly could
I think it would be a tad overkill, tbh, but you could do it