Skip to content

Invoke Build Callbacks at Lifetime Scope Creation #1054

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

Merged
merged 5 commits into from
Dec 4, 2019

Conversation

alistairjevans
Copy link
Member

@alistairjevans 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 December 3, 2019 16:43
…iner, and switch the build callbacks to behave like a registered component that gets resolved at container build time or lifetime scope creation time.
Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we can remove the nullable notes we're good.

Copy link
Member

@tillig tillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

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

Successfully merging this pull request may close these issues.

Enable build callbacks to run when registered in child lifetime scopes
2 participants