My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
PropertyInjection  
Property injection uses writeable properties rather than constructor parameters to perform injection.
Autofac2
Updated Aug 6, 2010 by nicholas...@gmail.com

Introduction

If the component is a delegate, use an object initialiser.

builder.Register(c => new A { B = c.Resolve<B>() });

To support circular dependencies, use an activated event handler:

builder.Register(c => new A()).OnActivated(e => e.Instance.B = e.Context.Resolve<B>());

Via reflection, use the PropertiesAutowired() modifier to inject properties:

builder.RegisterType<A>().PropertiesAutowired();

If you know the property name and value in advance, you can use builder.WithProperty("propertyName", propertyValue).

Comment by tahir.ah...@gmail.com, Jul 14, 2010

Replace InjectProperties? with PropertiesAutowired?.

Comment by project member nicholas...@gmail.com, Jul 15, 2010

Done, thanks.

Comment by tahir.ah...@gmail.com, Jul 26, 2010

Is it possible to wire certain properties on all sub-classes of a specific base class?

class A { ... public int P { get;set; } ... }

class B:A { } class C:A { }

...

builder.Register<B>(); // using 1.4 builder.Register<C>(); // using 1.4

// i need A.P to be 5 on both B and C (and all other sub-classes)

Comment by adnan.hu...@danatev.com, Jun 23, 2011

I'm sorry but I didn't understand the statement "If a component is a delegate".

Comment by lcorneliussen@gmail.com, May 11, 2012

Is it possible to configure the Builder to always autowire properties?


Sign in to add a comment
Powered by Google Project Hosting