Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module.AttachToComponentRegistration not Running for Lifetime Scope Registrations #506

Closed
tillig opened this issue Mar 20, 2014 · 2 comments

Comments

@tillig
Copy link
Member

tillig commented Mar 20, 2014

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.
}

A more comprehensive example is shown in this gist. The original discussion of this issue is on the Autofac user group.

@nblumhardt
Copy link
Member

Duplicate of #218 I think?

@tillig
Copy link
Member Author

tillig commented Mar 20, 2014

DOH! Yup. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants