0

そこで、NuGet から最新の MT を取り出して、強盗のようにそれを使ってコーディングを行ってきました。これまでのところそれが大好きです。現在私が実装しているシナリオは、実装の 1 つが MT である汎用の「バス」ラッパーです。したがって、MT の具体的な実装では、バスをコンストラクターに実装します...「登録」と呼びましょう

    /// <summary>
    /// Registers this instance with a particular bus. Every instance with the same name
    /// will end up on the same bus
    /// </summary>
    /// <param name="networkName">The common key to share with other instances on the network</param>
    public void Register(string networkName)
    {
        _bus = ServiceBusFactory.New(x =>
        {
            x.ReceiveFrom("msmq://localhost/the_wheels_on_the_bus");
            x.SetPurgeOnStartup(true);
            x.SetNetwork(networkName);
            x.UseMsmq();
            x.UseMulticastSubscriptionClient();
        });
    }

現在、抽象メンバーにより、外部コードはこの実装を使用してハンドラーを登録できます。

    /// <summary>
    /// Abstract method to implement on the bus for allow for Responding to Request/Response calls
    /// </summary>
    /// <typeparam name="TIn">The message to be received from the requester.<remarks>Implements <see cref="ICorrelatedMessage"/>ICorrelatedMessage</remarks> and must have a value</typeparam>
    /// <typeparam name="TOut">The message to be returned to the requester.<remarks>Implements <see cref="ICorrelatedMessage"/>ICorrelatedMessage</remarks> and must have a value</typeparam>
    /// <param name="hostedClassesFunc">The func to invoke to get the appropriate data</param>
    protected override void RegisterHandler<TIn, TOut>(Func<TIn, TOut> hostedClassesFunc)
    {
        _bus.SubscribeHandler<TIn>(msg =>
            {
                var output = hostedClassesFunc.Invoke(msg);
                var context = _bus.MessageContext<TIn>();
                context.Respond(output);
            });

        if (typeof(TIn).GetInterfaces().Contains(typeof(ICachableItem))
        {
            //mark it as a worker
            //_bus.Worker ?? <-- How can i register this guy here?
        }
    }

ここで質問があります。ここで労働者を登録することはできますか? この時点で、バスに労働者を注入する場所が見つからないようです。

助けてくれてありがとう..コードが正しく見えるようになることを願っています

4

2 に答える 2

0

現在、構成ブロックの外でこれを行う方法はありません。バスが作成された後にこれを行うには、何らかの方法でこれを公開する必要があります。

于 2013-09-05T23:32:54.160 に答える