如何使用Windsor Container向Akka.Net中的actor添加存储

时间:2017-02-17 09:50:47

标签: c# akka akka.net

这是我尝试向演员添加Stash

class Program
{
    static void Main(string[] args)
    {
        var actorSystem = ActorSystem.Create("mySystem");

        var container = new WindsorContainer();
        container.Install(new CommonWindsorInstaller());

        // ReSharper disable once ObjectCreationAsStatement
        new WindsorDependencyResolver(container, actorSystem);

        var rootActor = actorSystem.ActorOf(actorSystem.DI().Props<RootActor>(), typeof(RootActor).Name);

        rootActor.Tell(new CreateChildMessage());

        Console.ReadLine();
    }
}

internal class CreateChildMessage
{
}

internal class CommonWindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Component.For<RootActor>().Named("RootActor").LifestyleTransient());
        container.Register(Component.For<ChildActor>().Named("ChildActor").LifestyleTransient());
        container.Register(Component.For<IChildActor>().ImplementedBy<ChildActor>().Named("IChildActor").LifestyleTransient());

    }
}

internal class RootActor : ReceiveActor
{
    public RootActor()
    {
        Receive<CreateChildMessage>(
            m =>
                {
                    var child = ActorHelper.CreateActor(Context, typeof(IChildActor), "child");
                });
    }
}

public interface IChildActor
{
}

public class ChildActor : ReceiveActor, IChildActor, IWithUnboundedStash
{
    public IStash Stash { get; set; }
}

public static class ActorHelper
{
    public static IActorRef CreateActor(IUntypedActorContext context, Type actorType, string name)
    {
        var actorName = actorType.Name + "." + name;

        var actor = context.Child(actorName);
        if (!actor.Equals(ActorRefs.Nobody))
        {
            return actor;
        }

        var actorProps = context.DI().Props(actorType);
        actor = context.ActorOf(actorProps, actorName);

        return actor;
    }
}

不幸的是,我遇到了以下异常:

    [ERROR][17.02.2017 9:39:19][Thread 0004][ActorSystem(mySystem)] An exception occurred while trying to apply plugin of type Akka.Actor.ActorStashPlugin to the newly created actor (Type = Akka.Stash.ChildActor, Path = akka://mySystem/user/RootActor/IChildActor.child)
Cause: System.NotSupportedException: DequeBasedMailbox required, got: Mailbox
An (unbounded) deque-based mailbox can be configured as follows:
    my-custom-mailbox {
        mailbox-type = "Akka.Dispatch.UnboundedDequeBasedMailbox"
    }
   at Akka.Actor.Internal.AbstractStash..ctor(IActorContext context, Int32 capacity)
   at Akka.Actor.StashFactory.CreateStash(IActorContext context, Type actorType)
   at Akka.Actor.ActorStashPlugin.AfterIncarnated(ActorBase actor, IActorContext context)
   at Akka.Actor.ActorProducerPipeline.AfterActorIncarnated(ActorBase actor, IActorContext context)

编辑

我可以通过IChildActor的{​​{1}}后代来消除这个错误,即

IWithUnboundedStash

但这不是选项,我不希望我的所有public interface IChildActor: IWithUnboundedStash { } public class ChildActor : ReceiveActor, IChildActor { public IStash Stash { get; set; } } 实施都有藏匿

编辑2 以下是重现https://github.com/bonza/Akka.Net.CastleWindsor.Stash/

的GitHub存储库

0 个答案:

没有答案