My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
MethodInjection  
Method injection sets dependencies by calling a method.
Autofac2
Updated Apr 24, 2011 by nicholas...@gmail.com

Introduction

Method injection can be achieved one of two ways.

Using the Activator

If using a delegate activator, just call the method in the activator:

builder.Register(c => {
  var result = new Whatever();
  result.SetSomeDependency(c.Resolve<SomeType>());
  return result;
});

Using an Activating Handler

If you're using another activator, e.g. the reflection activator, create a handler for the Activating event:

builder.Register<Whatever>().OnActivating(e => e.Instance.SomeMethod());

Sign in to add a comment
Powered by Google Project Hosting