简体   繁体   中英

How to register IFilter<PublishContext<T>> in MassTransit when using Autofac extensions

I am using Autofac extensions and can't find how to register IFilter<PublishContext<T>> which has dependencies. The docs suggest to use UsePublishFilter(typeof(TFilter<>), context) but where to get the context ?

public static ContainerBuilder RegisterMassTransit(this ContainerBuilder builder, Func<IBusRegistrationContext, IBusControl> createBusFunc, Assembly consumerAssembly = null)
{
    builder.AddMassTransit(cfg =>
    {
        if (consumerAssembly != null)
        {
            cfg.AddConsumers(consumerAssembly);
        }

        cfg.AddBus(createBusFunc);
    });

    return builder;
}

public void ConfigureContainer(ContainerBuilder builder)
{
    builder
        .RegisterMassTransit(CreateBus, Assembly.GetExecutingAssembly())
        .RegisterTelemetryCollector();
}

private IBusControl CreateBus(IBusRegistrationContext registrationContext)
{
    return Bus.Factory.CreateUsingAzureServiceBus(
        cfg =>
        {
            cfg.Host(_serviceBusConnectionString);

            cfg.UsePublishFilter(typeof(MyFilterWithDependencies<>), ????);
        });
}

There is seemingly an overload but where to get the ILifetimeScopeProvider ?

public static void UsePublishFilter(this IPublishPipelineConfigurator configurator, Type filterType, ILifetimeScopeProvider lifetimeScopeProvider)

您应该将registrationContext作为第二个参数传递。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM