Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3849384
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:50:48+00:00 2026-05-19T16:50:48+00:00

newbie here, sorry if this is an obvious question. I’ve read from this page:

  • 0

newbie here, sorry if this is an obvious question.

I’ve read from this page: http://code.google.com/p/autofac/wiki/NewInV2

In Autofac 1, weak references are held by the container. This makes sense if the objects being referenced use disposal to release GC/finalizer resources, but if the dispose method contains application logic then GC timing could introduce unexpected behaviour.

Autofac 2 holds normal references. To opt out of this behaviour and mange disposal manually, use the ExternallyOwned registration modifier.

Is that mean when I need to release an object that is resolved by Autofac to the GC, I cannot simply say:

a = null;

because Autofac holds a strong reference to the object. Instead, I should use Owned<>:

public class MyClass
{
    public MyClass(Owned<A> a)
    {
        a.Value.Dosomething();
        a.Dispose();
    }
}

or use the ExternallyOwned registration modifier:

builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).ExternallyOwned();

later on, I should be able to use a = null to release the object to the GC.

Is that right?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:50:48+00:00Added an answer on May 19, 2026 at 4:50 pm

    By default, you don’t need to dispose anything – Autofac will automatically identify and dispose any IDisposable instances it created when their containing lifetime scope is disposed.

    You only need to use Owned<T> or ExternallyOwned() if you have a reason to manage the lifetime of the object manually. If you resolve an Owned<T> then you should call t.Dispose() yourself – the common usage pattern is to take a dependency on a factory delegate:

    public class MyClass
    {
        private Func<Owned<User>> myDisposableFactory;
    
        public MyClass(Func<Owned<User>> myDisposableFactory)
        {
            this.myDisposableFactory = myDisposableFactory;
        }
    
        public void DoSomething()
        {
            using (var disposable = this.myDisposableFactory())
            {
                // ...
                disposable.Dispose();
            }
        }
    }
    

    If you register a type as ExternallyOwned() then Autofac will not dispose of any resolved instance when the containing lifetime scope ends – it’s up to you to manage it.

    Take a look at Nicholas Blumhardt’s article on lifetimes for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

newbie here, sorry if this is an obvious question, and sorry for my English.
I'm sure this is a newbie question so sorry in advance. I've read a
Sorry for this maybe foolish question but i'm newbie to SQL Server. Here structure
Here is one more newbie question: require 'tasks/rails' I saw this line in Rakefile
Hi Sorry for this noob question but here goes...i have a working slidetoggle on
currently i'm studying MySQL, sorry for my newbie question. Here my question I have
Im sorry if this is a newbie question but I'm getting confuse about how
Just starting with php and sorry if this is a newbie question but i'm
Sorry this is a very newbie question. We have this massive application I am
I'm sorry if this is a newbie question, but it seems I don't get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.