所以我刚刚从 NuGet 中提取了最新的 MT,并且一直像强盗一样使用它进行编码。爱它至今。现在我正在实现的场景是一个通用的“总线”包装器,其中一个实现是 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?
}
}
所以问题就在这里,我什至可以在这里注册一个工人吗?在这一点上,我似乎找不到任何地方可以在公共汽车上注射工人。
提前感谢您的帮助..我希望代码最终看起来正确