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

Add an event that signals when the container is about to get locked #767

Closed
dotnetjunkie opened this issue Nov 6, 2019 · 1 comment
Closed
Labels
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented Nov 6, 2019

The Container Locking event would be raised just before the container is about to be locked, giving the developer a last change to interact and change the unlocked container before it is sealed for further modifications. Locking typically occurs by a call Container.GetInstance, Container.Verify, or any other method that causes the construction and resolution of registered instances.

This events allows a developer to register types, hook unregistered type resolution events that need to be applied last, or see who is responsible for locking the container. A registered event handler delegate is allowed to make a call that locks the container, e.g. calling Container.GetInstance; this will not cause any new ContainerLocking event to be raised. Doing so, however, is not advised, as that might cause any following executed handlers to break, in case they require an unlocked container.

Example:

container.Options.ContainerLocking += (s, e) =>
{
    // Do some last checks
    if (!container.GetCurrentRegistrations().Any(r => r.ServiceType.IsSubClassOf(Controller))
        throw new Exception("Why no Controllers, bro?");

    // Make some last-minute registrations
    container.ResolveUnregisteredType += (_, __) => { ... };

    container.GetInstance<MyType>();
};
@dotnetjunkie dotnetjunkie added this to the v4.8 milestone Nov 6, 2019
@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator Author

@dotnetjunkie dotnetjunkie commented Nov 6, 2019

feature-767 branch created.

dotnetjunkie added a commit that referenced this issue Nov 6, 2019
dotnetjunkie added a commit that referenced this issue Nov 17, 2019
dotnetjunkie added a commit that referenced this issue Nov 23, 2019
dotnetjunkie added a commit that referenced this issue Nov 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.