These are chat archives for akkadotnet/akka.net

31st
Oct 2016
Bart de Boer
@boekabart
Oct 31 2016 09:00
I can't believe I'm asking this, feeling it should be trivial, but, how can an actor easily get an IActorRef (or 'null') for a child with a particular name?
Gregorius Soedharmo
@Arkatufus
Oct 31 2016 09:03
mySystem.ActorSelection(Self.Path + "/child");?
just an idea, never tried it myself
or you can do Context.Child(name)...
Marc Piechura
@marcpiechura
Oct 31 2016 09:46
Keep in mind, they don't return null if the child doesn't exists but instead Nobody.Instance
Bart de Boer
@boekabart
Oct 31 2016 10:28
Of course... thanks guys!
Gregorius Soedharmo
@Arkatufus
Oct 31 2016 13:42
would a generic class message survive serialization to remote nodes?
Damian Reeves
@DamianReeves
Oct 31 2016 14:54
Where can I find consistent guidance on how to implement a DI extension. When I look at the various DI repos it is unclear why they operate the way they do. What lifecycle should things be registered as, and etc are not clear. I've got an implementation that fails some of the DiResolverSpec tests but its unclear what is wrong and what is right
Here's an example of my Resolver:
    public class ServiceProviderDependencyResolver : IDependencyResolver
    {
        private readonly ConcurrentDictionary<string, Type> _typeCache;
        private readonly IServiceProvider _serviceProvider;
        private readonly ActorSystem _system;
        private readonly ConditionalWeakTable<ActorBase, IServiceScope> _references;

        public ServiceProviderDependencyResolver(IServiceProvider serviceProvider, ActorSystem system)
        {
            if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider));
            if (system == null) throw new ArgumentNullException(nameof(system));
            _typeCache = new ConcurrentDictionary<string, Type>(StringComparer.InvariantCultureIgnoreCase);
            _serviceProvider = serviceProvider;
            _system = system;            
            _system.AddDependencyResolver(this);
            _references = new ConditionalWeakTable<ActorBase, IServiceScope>();
        }
        public Type GetType(string actorName)
        {
            return _typeCache.GetOrAdd(actorName, key => key.GetTypeValue());
        }

        public Func<ActorBase> CreateActorFactory(Type actorType)
        {
            return () =>
            {
                var scopeFactory =_serviceProvider.GetService<IServiceScopeFactory>();
                var scope = scopeFactory.CreateScope();
                var actor = (ActorBase)scope.ServiceProvider.GetService(actorType);
                return actor;
            };
        }

        public Props Create<TActor>() where TActor : ActorBase
        {
            return Create(typeof(TActor));
        }

        public Props Create(Type actorType)
        {
            return _system.GetExtension<DIExt>().Props(actorType);
        }

        public void Release(ActorBase actor)
        {
            IServiceScope serviceScope;
            if (_references.TryGetValue(actor, out serviceScope))
            {
                serviceScope.Dispose();
                _references.Remove(actor);
            }
        }
    }
Arjen Smits
@Danthar
Oct 31 2016 15:45
@DamianReeves for which DI framework are you creating an extension ?
Damian Reeves
@DamianReeves
Oct 31 2016 15:53
Microsoft.Extensions.DependencyInjection
essentially trying to abstract away that choice through the conforming container they provide
Arjen Smits
@Danthar
Oct 31 2016 17:06
As far as lifecycles go
They should be scoped to the lifetime of the actor. Which is why scopes are created in the CreateActorFactory, and subsequently tracked so they are properly disposed.
Lifetime's of the dependancy should be transient, or, to make a parralel with Autofac. InstancePerDependancy, or per lifetime scope.
But there are no fixed rules for that. The DI Resolver takes care of making sure that there is one scope per actor.
But that still allows you to register a singleton in your global scope, and use it in your actors
Damian Reeves
@DamianReeves
Oct 31 2016 17:10
So the primary idea is a scope per actor
Arjen Smits
@Danthar
Oct 31 2016 17:10
Yes.
Which unit tests are failing ?
Damian Reeves
@DamianReeves
Oct 31 2016 17:12
The confusing part is all the different unit tests for the various containers have setups at different scopes: Transient, Hiearchical, per container, etc
Arjen Smits
@Danthar
Oct 31 2016 17:14
Yes. Thats to test that the resolver works properly for each scenario
The thing that you need to keep in mind here is that the resolver creates this scope. To make sure that transient registered dependencies are actually scoped to the lifetime of the actor.
All other scopes (singleton, percontainer, etc). Don't have to adhere to that constraint, but they should still work as expected ;)
Damian Reeves
@DamianReeves
Oct 31 2016 17:16
Ok. So I see the problem with my code is I seem to have not properly tracked the scope creation in CreateActorFactory
Damian Reeves
@DamianReeves
Oct 31 2016 17:50
blob
So those are the failing tests
Arjen Smits
@Danthar
Oct 31 2016 18:50
ah. Those are actually problems in the DI testkit
i did a PR to fix that a short while ago. it was merged
Ill bet that if you compile that against source the tests should pass
Damian Reeves
@DamianReeves
Oct 31 2016 20:33
cool... will take a look. One of them passes when I run them individually so I thought the tests were a bit unstable
Aaron Stannard
@Aaronontheweb
Oct 31 2016 20:37
@alexvaluyskiy it is possible to do that, just need to add an IOutputTarget or whatever the class is called in NBench
Vlad Kosarev
@vladkosarev
Oct 31 2016 22:29
hey guys, would anyone have any clue why actorSystem.Terminate() takes a couple of orders of magnitude longer if we run our tests in Debug mode vs Run mode?
Aaron Stannard
@Aaronontheweb
Oct 31 2016 22:51
@vladkosarev hmmm
I might
gotta check something rq though, because I think it's supposed to be off unless the Akka code itself is modified by the end user
ok nope, not it
we have some code you can turn on for doing debugging on the actorcell, but you have to manually change a static variable and recompile akka to turn it on
so that wouldn't be the issue