/// <summary> /// 构造一个抽象代理。 /// </summary> /// <param name="source">给定的源实例(可选)。</param> /// <param name="dependency">给定的 <see cref="IInvokeDependency{TSource}"/>(可选)。</param> /// <param name="validation"></param> protected AbstractDependencyProxy(TInterface source = null, IInvokeDependency <TInterface> dependency = null, IInvokeValidation validation = null) { if (source.IsNotNull()) { Source = source; } Dependency = dependency ?? new InvokeDependency <TInterface>(); Validation = validation ?? new InvokeValidation(); }
/// <summary> /// First argument to the InvokeAsync method must be the MessageContext /// being passed along the pipeline. /// Othe arguments for this method are where it makes sense to create new objects /// per message rather than 1 object created for the constructor injection. /// As in constructor dependency inject, dependencies must be wired up with the IoC /// container as part of application startup /// </summary> /// <param name="context">The message context being passed along the pipeline</param> /// <param name="invokeDependency">A dependency to instantiate per message rather than per middleware object</param> /// <returns></returns> public Task InvokeAsync(MessageContext context, IInvokeDependency invokeDependency) { _logger.LogDebug("InvokeAsync called"); // You can access the message from RabbitMQ here: var messageFromRabbit = context.GetRabbitMqMessage(); // Add any processing, ETL, transforms, filtering etc. // Call some dependencies, maybe? _dependency.RunSomeMethod(invokeDependency.GetSomeValue()); return(_next(context)); }