question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: How do you destroy a scoped container?

See original GitHub issue

I’m currently using typedi in an HTTP application and I’m creating a scoped container per request to ensure there’s no bleed from other requests that are in flight.

At the end of the request I call .reset() on the scoped container and I also set the scoped container to null. However, when profiling the application with Chrome Dev Tools I can see that the container instances are still in memory and even after calling .reset() I’m still able to retrieve different container instances back with .get().

I’m just wondering if I’m missing something or perhaps my usage of typedi is incorrect?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
attilaoroszcommented, May 17, 2022

@mzyrc Thanks for the detailed report! So it seems like the container registry is not released yet so unfortunately there is no official way to dispose of a container (that i know of). There is a workaround tho:

const index = Container['instances'].findIndex((instance: any) => instance.id === containerId);
if (index > -1) {
  Container['instances'].splice(index, 1);
}

This is obviously very hacky, but if you have a critical project needing this right now, there you go.

@NoNameProvided Do you have a schedule for the next release?

0reactions
mzyrccommented, May 17, 2022

Hi @attilaorosz

Thanks for such a quick turn around, I can confirm the workaround worked great šŸ‘

If I can help at all with the upcoming release I’d be happy to lend a hand

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring - How can I destroy my prototype-scoped beans?
Spring will create the prototype bean required by your code, but will not destroy it. This behaviour is by design as it is...
Read more >
Object Lifetime Management — Simple Injector 5 documentation
Instances will be disposed when the container is disposed. Many different platform and framework-specific flavors are available for the Scoped lifestyle. PleaseĀ ...
Read more >
Service Lifetimes in a Nutshell - { Between Two Brackets }
When we create our service container and reference a scoped provider instance, the service scope in reference will internally call Dispose atĀ ...
Read more >
Introduction to Contexts and Dependency Injection - Quarkus
Well, a bean is a container-managed object that supports a set of basic services, ... What scopes can I actually use in my...
Read more >
Dependency Injection and Service Lifetimes in .NET Core
NET Core has a native Dependency Injection container, but you can also use another ... Scoped — Services are created on each request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found