Difference between "Ownership" in error stracktrace?

8 views
Skip to first unread message

bruce...@gmail.com

unread,
Apr 5, 2017, 9:37:48 AM4/5/17
to Autofac
I'm currently trying to resolve an issue and in my Windows Application event log I am seeing some error stack traces that mention AutoFac registration.

My question in particular is what do the following mean?:
- Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope

- Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = ExternallyOwned

What is the difference between OwnedByLifetimeScope and ExternallyOwned?

Alex Meyer-Gleaves

unread,
Apr 5, 2017, 10:02:44 AM4/5/17
to Autofac
Hi Bruce,

Ownership determines who is responsible for tracking the disposal of an instance. There are only two valid values for this and you have shown both of them in your examples.

OwnedByLifetimeScope - The instances are disposed when the lifetime scope is disposed.
ExternallyOwned - The lifetime scope does not dispose the instances.

The ExternallyOwned option means that when the service was registered the disposal tracking feature was explicitly turned off.

builder.RegisterType<SomeComponent>().ExternallyOwned();

When the disposal tracking is in place any service that implements IDisposable will be disposed when the lifetime scope that manages it is disposed.

You can read a bit more about disposal tracking in the documentation.


Hope that provides some help in resolving your issue.

Cheers,

Alex.

bruce...@gmail.com

unread,
Apr 5, 2017, 6:01:55 PM4/5/17
to Autofac
Thanks!
Reply all
Reply to author
Forward
0 new messages