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
IRegistrationBuilder
are 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,
IRegistrationBuilder
instances are already gone. You have only theIComponentRegistration
instance in theResolveRequestContext.Registration
property.In detail
IRegistrationBuilder
is created thenRegistrationData
that contains theLifetime
,Metadata
,Options
,Ownership
andSharing
properties. The extension methods ofIRegistrationBuilder
actually configures these properties.IResolvePipelineBuilder
field you actually configure with the.ConfigurePipeline()
extension method.ContainerBuilder
instance with theIRegistrationBuilder
instance.ContainerBuilder.Build()
method.IComponentRegistration
from theIRegistrationBuilder
instance.IComponentRegistration
contains the same properties that come from theRegistrationData
and also gets the configuredIResolvePipelineBuilder
.