I would like to extend my service registration [e.g. EnableInterfaceInterceptors] from Autofac Pipeline. However, I couldn't find a way to achieve that. Is there any entrypoint for me to access the registration as IRegistrationBuilder?
Provided codes below for your reference
containerBuilder.RegisterGeneric(typeof(CredentialService<>)).InstancePerDependency()
.ConfigurePipeline(p =>
{
p.Use(PipelinePhase.RegistrationPipelineStart, (context, next) =>
{
// WHAT SHOULD I DO HERE TO GET BACK THE IRegistrationBuilder IN ORDER TO EXTEND MY REGISTRATION?
next(context);
});
});
Thanks in advance
Autofac docs
In short
Although it is called registration pipeline, it is actually used when a resolve request occurs.
Instances of
IRegistrationBuilderare not stored anywhere except in the configuration callback (see details below), hence you cannot access them in the pipeline in any way.By the time your pipeline delegate is being executed,
IRegistrationBuilderinstances are already gone. You have only theIComponentRegistrationinstance in theResolveRequestContext.Registrationproperty.In detail
IRegistrationBuilderis created thenRegistrationDatathat contains theLifetime,Metadata,Options,OwnershipandSharingproperties. The extension methods ofIRegistrationBuilderactually configures these properties.IResolvePipelineBuilderfield you actually configure with the.ConfigurePipeline()extension method.ContainerBuilderinstance with theIRegistrationBuilderinstance.ContainerBuilder.Build()method.IComponentRegistrationfrom theIRegistrationBuilderinstance.IComponentRegistrationcontains the same properties that come from theRegistrationDataand also gets the configuredIResolvePipelineBuilder.