|
PropertyInjection
Property injection uses writeable properties rather than constructor parameters to perform injection.
Autofac2 IntroductionIf 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). | |
► Sign in to add a comment
Replace InjectProperties? with PropertiesAutowired?.
Done, thanks.
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)
I'm sorry but I didn't understand the statement "If a component is a delegate".
Is it possible to configure the Builder to always autowire properties?