Replies: 1 comment 6 replies
-
Do you happen to have a repro? I can look into this more when back from
Vacation to see if we can enhance the expression handling in some way...
As far as the reason for an expression rather than a function, my general
assumption is that because Props are intended to be serializable, an
expression is typically easier to decompose into a constructor and args.
That said, we may be able to add some form of static factory for the parser
(we already have some custom parse logic to try and avoid .Compile()) but
an example case will make it easier per above.
…On Mon, Feb 26, 2024, 2:31 PM chylex ***@***.***> wrote:
The Props Create<TActor>(Expression<Func<TActor>> factory) overload takes
an Expression, which if it is a NewExpression, creates Props with an
ActivatorProducer. When I use the recommended static factory method, it
makes sense to me (and Rider recommends this) to make the actor constructor
private. However, this crashes at runtime, because Activator cannot call
private constructors.
This is really confusing to me, so I'm wondering what's the rationale?
Normally in .NET, if an Expression calls a private constructor, compiling
it and calling it elsewhere works - except in Akka.NET - making Akka.NET's
behavior counter-intuitive.
It's also not clear why use an Expression at all, as opposed to a Func.
The Props class already includes a FactoryConsumer implementation that
works with a Func, but as far as I can tell, FactoryConsumer is not used
anywhere.
I might try copying FactoryConsumer and using it via Props.CreateBy, so I
can make actor constructors private and avoid Activator, but I guess
there's a good reason why Akka.NET doesn't work this way by default?
—
Reply to this email directly, view it on GitHub
<#7104>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC7UYVJJ5LQRLPB3XS3BSATYVTPIRAVCNFSM6AAAAABD2ZFPNSVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZWGI3TONBSGU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
chylex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The
Props Create<TActor>(Expression<Func<TActor>> factory)
overload takes anExpression
, which if it is aNewExpression
, createsProps
with anActivatorProducer
. When I use the recommended static factory method, it makes sense to me (and Rider recommends this) to make the actor constructor private. However, this crashes at runtime, becauseActivator
cannot call private constructors.This is really confusing to me, so I'm wondering what's the rationale?
Normally in .NET, if an
Expression
calls a private constructor, compiling it and calling it elsewhere works - except in Akka.NET - making Akka.NET's behavior counter-intuitive.It's also not clear why use an
Expression
at all, as opposed to aFunc
. TheProps
class already includes aFactoryConsumer
implementation that works with aFunc
, but as far as I can tell,FactoryConsumer
is not used anywhere.I might try copying
FactoryConsumer
and using it viaProps.CreateBy(IIndirectActorProducer)
, so I can make actor constructors private and avoidActivator
, but I guess there's a good reason why Akka.NET doesn't work this way by default?Beta Was this translation helpful? Give feedback.
All reactions