My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
OnActivatingActivated  
Perform processing at different points in the component lifecycle.
Autofac2
Updated Mar 1, 2011 by kaleb.pe...@gmail.com

Autofac exposes events that can be hooked at various stages in instance lifecycle:

  • OnActivating
  • OnActivated
  • OnRelease

These are subscribed to during component registration (or alternatively by attaching to the IComponentRegistration interface.

builder.RegisterType<Listener>()
   .OnActivated(e => e.Instance.StartListening());

OnActivating

Called before a component is used. Here you can:

  • Switch the instance for another or wrap it in a proxy
  • Do property injection
  • Perform other initialisation tasks

OnActivated

Called once a component is fully constructed. Here you can perform application-level tasks that depend on the component being fully constructed - these should be rare.

OnRelease

Replaces the standard cleanup behaviour for a component. The standard cleanup behavior of components that implement IDisposable and that are not marked as ExternallyOwned is to call the Dispose method. The standard cleanup behavior for components that do not implement IDisposable or are marked as externally owned is a noop - to do nothing. OnRelease overrides this behavior with the provided implementation.


Sign in to add a comment
Powered by Google Project Hosting