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

Invoke Build Callbacks at Lifetime Scope Creation #1054

merged 5 commits into from Dec 4, 2019


Copy link

alistairjevans commented Dec 3, 2019

Following the discussion in #985, these changes allow build callbacks to execute at the point of lifetime scope creation if new ones have been registered.

So, this works:

var scope = container.BeginLifetimeScope(cfg =>
    cfg.RegisterBuildCallback(scope => { /* do something */ });

The callback will be invoked just prior to BeginLifetimeScope exiting, after any startable components are instantiated (same behaviour as the Container).

As discussed, we now register a component BuildCallbackService that contains the set of callbacks to register; nested scopes then add replacement registrations of that service.

BuildCallbackManager is responsible for executing the callbacks.

Fixes #985

Alistair Evans added 3 commits Dec 3, 2019
…iner, and switch the build callbacks to behave like a registered component that gets resolved at container build time or lifetime scope creation time.
Alistair Evans
Copy link

tillig left a comment

I think this is a nice, elegant way to solve the whole thing and unify the way callbacks are done. Great job!

src/Autofac/Builder/BuildCallbackService.cs Outdated Show resolved Hide resolved
Copy link

tillig left a comment

I think if we can remove the nullable notes we're good. Outdated Show resolved Hide resolved
Alistair Evans
tillig approved these changes Dec 4, 2019
Copy link

tillig left a comment


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

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.