コード例 #1
0
        public async Task ActorSingleChainTest()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ActorNode>().As <IActorNode>();
            builder.RegisterType <ActorSum>().As <IActorSum>();
            ILifetimeScope container = builder.Build();

            IActorManager manager = new ActorManagerBuilder()
                                    .Register <IActorNode>((c, k, m) => container.Resolve <IActorNode>(new TypedParameter(typeof(ActorKey), k), new TypedParameter(typeof(IActorManager), m)))
                                    .Register <IActorSum>((c, k, m) => container.Resolve <IActorSum>(new TypedParameter(typeof(ActorKey), k), new TypedParameter(typeof(IActorManager), m)))
                                    .Build();

            using (container)
            {
                ActorKey   key  = new ActorKey("node/test");
                IActorNode node = await manager.CreateProxyAsync <IActorNode>(_context, key);

                int sum = 0;
                for (int i = 0; i < 10; i++)
                {
                    await node.Add(_context, i);

                    sum += i;
                }

                IActorSum sumActor = await manager.CreateProxyAsync <IActorSum>(_context, new ActorKey(sumActorName));

                (await sumActor.GetSum()).Should().Be(sum);
            }

            await manager.DeactivateAllAsync(_context);
        }
コード例 #2
0
        public async Task ActorSingleChainTest()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ActorNode>().As <IActorNode>();
            builder.RegisterType <ActorSum>().As <IActorSum>();
            ILifetimeScope container = builder.Build();

            IActorManager manager = new ActorConfigurationBuilder()
                                    .Register <IActorNode>(_ => container.Resolve <IActorNode>())
                                    .Register <IActorSum>(_ => container.Resolve <IActorSum>())
                                    .Build()
                                    .ToActorManager();

            using (container)
            {
                ActorKey   key  = new ActorKey("node/test");
                IActorNode node = await manager.CreateProxy <IActorNode>(key);

                int sum = 0;
                for (int i = 0; i < 10; i++)
                {
                    await node.Add(_context, i);

                    sum += i;
                }

                IActorSum sumActor = await manager.CreateProxy <IActorSum>(new ActorKey(sumActorName));

                (await sumActor.GetSum()).Should().Be(sum);
            }

            await manager.DeactivateAll();
        }
コード例 #3
0
        public async Task ActorSingleChainTest()
        {
            using IActorHost actorHost = new ActorHost(_loggerFactory)
                                         .Register <IActorNode>(() => new ActorNode())
                                         .Register <IActorSum>(() => new ActorSum());

            ActorKey   key  = new ActorKey("node/test");
            IActorNode node = actorHost.GetActor <IActorNode>(key);

            int sum = 0;

            for (int i = 0; i < 10; i++)
            {
                await node.Add(i);

                sum += i;
            }

            IActorSum sumActor = actorHost.GetActor <IActorSum>(new ActorKey(sumActorName));

            (await sumActor.GetSum()).Should().Be(sum);

            await actorHost.DeactivateAll();
        }