Stephen York
Stephen York

Reputation: 1429

Autofac Module missing Preparing event

We have an Autofac module which was created with pre v5 and now that we're using upgraded nuget packages which use v6+ we're getting downgrade errors in the calling project. So forcing the upgrade IComponentRegistration no longer has the Preparing event that we can use in our LoggerModule. enter image description here

Does anyone know what needs to be done to make this Module's OnPreparing subscription support version 6+?

Upvotes: 2

Views: 1640

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26450

Check the upgrade documentation here: https://autofaccn.readthedocs.io/en/latest/whats-new/upgradingfrom5to6.html

RegistrationBuilder.RegistrationData no longer exposes the configured ActivatedHandlers, ActivatingHandlers or PreparingHandlers, and IComponentRegistration no longer exposes Preparing, Activating or Activated events.

All Autofac events are now implemented as CoreEventMiddleware added to the resolve pipeline.

If you need to inspect the set of event handlers added to the registration, you can inspect the registered middleware for instances of CoreEventMiddleware:

// Check if the registration has an OnActivated handler.
if (registration.ResolvePipeline.Middleware.Any(c => c is CoreEventMiddleware ev && ev.EventType == ResolveEventType.OnActivated))
{
}

The new logger example might also help https://autofaccn.readthedocs.io/en/latest/examples/log4net.html:

Upvotes: 3

Related Questions