Hook/Extension point modifying IRegistrationBuilder
See original GitHub issue(I’m not 100% sure that this isn’t possible today but afaik it isn’t…)
Problem Statement
We use our own little aop fw for our services. To use this in combination with autofac we use the same technique as eg autofac.extras.dynamicproxy does, having an extension method that replaces the implemented type of the service. It works fine but as we want this for all our services (replace registered service type with our generated one), it would be nice if there was any hook/extension point or similar in autofac that would be called for every registered component so we could skip this ext method call for each and every registration (many, many, many registrations in our system).
Desired Solution
Don’t know the inner working of autofac good enough to have a good suggestion. AttachToRegistrationSource
and Registered
event seem to happen “too late”.
Would it be possible to inject something to ContainerBuilder that will be called for each registration maybe?
Alternatives You’ve Considered
We can create a composition for ContainerBuilder and extend its methods behavior there. Or we could create our own extension methods directly on ContainerBuilder. Still, would be great if a “registration hook” would be available in autofac itself, especially for us with a big legacy system with many different processes and containerbuilder instances.
Issue Analytics
- State:
- Created a year ago
- Comments:12 (11 by maintainers)
Top GitHub Comments
OK, so after much going round the houses on a
ReplaceActivator
method, we realised we didn’t need to do any of it, because this scenario already “just works” using resolve pipeline middleware.If the desire from @RogerKratz is to replace the activator for all/some components, you can add middleware to do it. In the below example I create middleware that ignores the existing registered activator at resolve time, and uses its own. The middleware is added in the
Registered
method via thePipelineBuilding
event.Yes,
AttachToComponentRegistration
is just attached directly to theRegistered
event, and has access toIComponentRegistration
before the pipeline build happens.