vlingo-net / xoom-net-actors

Type safe Actor Model toolkit for reactive concurrency and resiliency using C# and other .NET languages.
Mozilla Public License 2.0
39 stars 18 forks source link

Type-safe constructor for Actor creation #81

Closed tjaskula closed 4 years ago

tjaskula commented 4 years ago

Today we crate the actor by the following way:

var definition =
                Definition.Has<InboundStreamActor>(Definition.Parameters(interest, addressType, reader, probeInterval),$"{inboundName}-inbound");
var inboundStream = stage.ActorFor<IInboundStream>(definition);

The goal would be to create the actor in the type-safe manner. Why ? Because it easier to be guided by the compiler what parameters to pass in the actor based on the type of actor. Instead we could do the following

var inboundStream = stage.ActorFor<IInboundStream>(() => new InboundStreamActor(interest, addressType, reader, probeInterval),$"{inboundName}-inbound"))

For that we would need to leverage creation through expressions like:

ActorFor<TActor>(Expression<Func<TActor>> factor)

For reference on JVM implementation (for impacted files rather than implementation details) : https://github.com/vlingo/vlingo-actors/commit/141f31b926e9534b2306c2768bdd4eefa3e2d519

VaughnVernon commented 4 years ago

@tjaskula I agree with this. Another way is to use an ActorInstantiator pattern. Currently in vlingo-java you can use a ActorInstantiator as a single lambda expression, because it is a @FunctionalInterface.

() -> new InboundStreamActor(interest, addressType, reader, probeInterval)

You can do this for the actorFor() that has the overload for an ActorInstantiator.

tjaskula commented 4 years ago

@VaughnVernon you mean that you pass () -> new InboundStreamActor(interest, addressType, reader, probeInterval)inside the actorFor() right ?

VaughnVernon commented 4 years ago

@tjaskula Correct.

tjaskula commented 4 years ago

Yes, so this should be similar to what I'm going to use on .NET side :)

VaughnVernon commented 4 years ago

Oh, ok. The above looked more verbose to me. I see now that I missed this code:

var inboundStream = stage.ActorFor<IInboundStream>(() => new InboundStreamActor(interest, addressType, reader, probeInterval),$"{inboundName}-inbound"))