You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In an Autofac.Module you can use the AttachToComponentRegistration method to handle component events like Preparing.
While this works well for components registered in the base container (with whatever lifetime scope), it does not work for components registered on the fly when a new lifetime scope is started.
var builder = new ContainerBuilder();
builder.RegisterModule<MyHandlerModule>();
// RootType will get handled by AttachToComponentRegistration because it
// is in the original set of registrations.
builder.RegisterType<RootType>();
var container = builder.Build();
using(var scope = container.BeginLifetimeScope(
b => b.RegisterType<LifetimeType>())
{
// LifetimeType will not get handled by AttachToComponentRegistration
// because it is registered on the fly.
}
In an Autofac.Module you can use the
AttachToComponentRegistration
method to handle component events likePreparing
.While this works well for components registered in the base container (with whatever lifetime scope), it does not work for components registered on the fly when a new lifetime scope is started.
A more comprehensive example is shown in this gist. The original discussion of this issue is on the Autofac user group.
The text was updated successfully, but these errors were encountered: