|
MethodInjection
Method injection sets dependencies by calling a method.
Autofac2 IntroductionMethod injection can be achieved one of two ways. Using the ActivatorIf 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 HandlerIf 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