zcz527 / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

AutofacControllerFactory doesn't dispose controllers #291

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I see the note and blank implementation in AutofacControllerFactory.cs:

        /// <summary>
        /// Releases the controller. Unecessary in an Autofac-managed application
        /// </summary>
        /// <param name="controller">The controller.</param>
        public override void ReleaseController(IController controller)
        {
        }

But this is causing my controllers to never be disposed.  For legacy reasons I 
manage my DB connections manually.  So I depend on Dispose() being called on 
the controller and thus my DB connections.  A work-around I've implemented is 
inheriting from AutofacControllerFactory and reimplementing ReleaseController() 
exactly as the DefaultControllerFactory does which gets the controllers 
disposing again.

Is there a specific reason to prevent AutofacControllerFactory from disposing 
controllers?

Original issue reported on code.google.com by abe.gill...@gmail.com on 4 Feb 2011 at 8:01

GoogleCodeExporter commented 8 years ago
Hi Abe, have you tried putting a breakpoint in your Dispose() method on a 
controller?

Autofac does dispose controllers - it just isn't necessary to do this 
explicitly via the controller factory.

If you're having problems with disposal in MVC2, please add the HTTP module to 
web.config as described on the MVC2 integration wiki page.

If you're having problems with MVC3, please follow up as this might indicate a 
bug.

Hope this helps!
Nick

Original comment by nicholas...@gmail.com on 4 Feb 2011 at 11:29

GoogleCodeExporter commented 8 years ago
Yes, logging and breakpoints; never a Dispose() called.  It's the reason I 
found the empty implementation.  I'm running MVC2 and, yes, have added the http 
module as per the wiki.  This is copy and pasted directly from my Web.config:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule, Autofac.Integration.Web" preCondition="managedHandler"/>
    </modules>
  </system.webServer>

Original comment by abe.gill...@gmail.com on 4 Feb 2011 at 11:34

GoogleCodeExporter commented 8 years ago
Thanks Abe. That't the config for IIS7 - is it possible your dev/test 
environment needs the IIS6 version?

Also just to brainstorm (not sure if Controller is disposable in MVC2 or not) - 
are you adding an implementation of IDisposable to the controller, or are you 
overriding the Dispose(bool) version?

If it is possible to repro this in a blank MVC2 project it would be extremely 
helpful if you could attach one.

Thanks!
Nick

Original comment by nicholas...@gmail.com on 5 Feb 2011 at 10:05

GoogleCodeExporter commented 8 years ago
OK, well after putting together a test case project, I found out that I 
apparently need to configure with the IIS6 version.  Which is odd, because I'm 
testing with VS.Net's debug ASP.Net server.  The template Web.config has a 
<system.webServer><modules> section and does NOT have a 
<system.web><httpModules>. You'd think the combo of running the latest dev 
environment and that very environment's Web.config template suggesting an IIS7 
setup would actually mean use an IIS7 config.  I guess the ASP.Net dev server 
is out of band from IIS proper.

In any case, my production environment was suffering the same issue.  But it's 
a Mono / Apache setup so it might also require the legacy config.

Sorry for the noise ... of course maybe this situation should be noted in the 
wiki.

Thanks.
-Abe

Original comment by abe.gill...@gmail.com on 6 Feb 2011 at 8:11

GoogleCodeExporter commented 8 years ago
Hi Abe,

Many thanks for following up - glad we tracked it down. I agree it is 
completely unexpected when running under VS.

Intrigued to hear more about your experiences using Autofac with Mono/Apache... 
if you ever have a chance to post some notes to the discussion group I'm sure 
others would be interested too.

Cheers,
Nick

Original comment by nicholas...@gmail.com on 6 Feb 2011 at 8:15

GoogleCodeExporter commented 8 years ago
No worries, thanks for looking into it so rapidly.  My comments about Autofac 
on Mono? ... nearly none except that it works completely as advertised (insofar 
as my use goes).

Original comment by abe.gill...@gmail.com on 6 Feb 2011 at 8:21