Most components that need to be cleaned up implement IDisposable, which Autofac will use when the component is due to be released. Some components however, notably WCF client proxies, have non-standard ‘release’ behaviour.
There have never been enough cases of these non-standard components to justify messing with the Autofac core model to provide custom release behaviours, so for some time (six major versions, in fact) this hasn’t been added.
Happily, for WCF proxies and other components like them, a simple implementation has been found that allows a custom release action to be piggy-backed on a regular disposable component, so in Autofac 2.3 (currently in preview) we’ll be offering OnRelease() for the first time:
.As<IClient>()
.OnRelease(client => ReleaseWcfClient(client));
Simple addition – hopefully a pleasant improvement in these scenarios.
For the curious, WCF client proxies require that calls to Dispose() be wrapped in try/catch blocks so that exceptions during disposal don’t obscure any other exceptions thrown during the use of the proxy itself. Not fun stuff, but relax, the Autofac.Integration.Wcf assembly now includes an implementation of UseWcfSafeRelease() as well.
[...] Coming in Autofac 2.3 – OnRelease() – Nicholas Blumhardt explains the new custom component release functionality which is being included in AutoFac 2.3, allowing the correct disposal for objects which require custom means of release beyond the standard IDisposable [...]
Whats the road map release date for Autofac 2.3 ?
This is probably a question for the project site, but there’s no obvious way to ask a question on the project site.
I have been learning Autofac while I have been studying Orchard CMS. I really like Autofac, but Orchard uses a builder notation that I cannot find documented anywhere. For example,
builder.RegisterType().As().As().SingleInstance();
{
builder.RegisterType().As().SingleInstance();
builder.RegisterType().As().SingleInstance();
{
builder.RegisterType().As().SingleInstance();
builder.RegisterType().As().SingleInstance();
}
}
This is an abbreviation, but you get the idea. Intuitively, this looks like a way to declare nested containers. However, my wife tends to assume things, and its not pretty. I don’t want assume too much; I’ll ask. What does this nested notation mean?
@wilk the best place to ask this one would be http://stackoverflow.com/questions/tagged/autofac – also tag your question with ‘Orchard’. As far as I can see the braces in your example are no-ops. Cheers!