1

I need a diagnostic/admin page to show what Autofac is managing at the current point in time. Good for finding leaks and bugs.

There is a way to count the number of objects Autofac has been resolving. However it's heavy and shouldn't be used in production.

There is a way to log all resolutions. Similarly, it shouldn't be used in production.

Unlike those solutions, all I need is a snapshot of currently managed objects. Is this possible, without capturing every resolution event and storing it (as done above)?

grokky
  • 8,537
  • 20
  • 62
  • 96

1 Answers1

1

Autofac will only create instances of services, except for IDisposable services it doesn't keep track of any services. If you want to have all resolved service, you will have to monitor and log them.

IDisposable instances are persisted in a private field of the private implementation of the IDisposer interface. Each ILifetimeScope contains its own IDisposer instances and there is no way to get all active ILifetimescope without keeping track of lifetimescope creation.

Keeping track of instances creation is not as heavy as it seems. Links you provide are good start point to implement such a feature. Don't forget to use WeakReference and ConditionalWeakTable to avoid any memory leak.

Cyril Durand
  • 15,834
  • 5
  • 54
  • 62