I'm having trouble defining binding using the ninja.
I am in a standard ASP.NET WebForms application. I have defined an HIL handler to inject dependencies into pages and control (property injection).
Here's what I'm trying to do:
Based on the value of ANUm on that combo box I am creating a custom combobox user control, I have a different object in a property I want to be able to inject (what I am trying to do is a little more involved than that, but the answer should be sufficient to go to me).
A conditional binding based on property value is not a good design and is not possible (at least Constructor injection) As the dependency is usually made before the received object. What will happen if the property changes later? The best way is to inject a factory or factory method, which requests an example from Niggs and internally exchange exchanges between the initial and asset value changes strategy.
Public Anman Entity Type {A, B} Public Class Microlrol: User Control [[Injection] Public Function & lt; Entity type, IMIFT display platex & gt; DisplayStrategyFactory {get this.factory; } Set {this.factory = value; This.UpdateEntityDisplayStrategy (); }} Public Entity Type Type {get {return.Type; } Set {this.type = value; This.UpdateEntityDisplayStrategy (); }; } Private UpdateEntityDisplayStrategy () {If (this.DisplayStrategyFactory! = Null) this.entityDisplayStrategy = this.DisplayStrategyFactory (this.type); }} Bind & lt; Func & lt; EntityType, IMyEntityDisplayStrategy & gt; & Gt; .aomind (ctax => gtk = gt; type == ctx.kernel.get> IMyEntityDisplayStrategy> (M = & gt; m.Get ("EntityType", EntityType.A)); Bind & Lt; IMyEntityDisplayStrategy & gt ;. & lt; AEntityDisplayStrategy & gt; (). Metadata ("EntityType", EntityType.A) binds & lt; IMyEntityDisplayStrategy & gt; & lt; BEntityDisplayStrategy & gt; () .WithMetaadata ("EntityType ", EntityType.B) Alternatively, add an activation action and dependency manually inject. But keep in mind that changing the barrier property will cause an inconsistent state.
On activation (ctx, e.g. RANK =) Example: MyStrategy = ctx.Cernel. (M => M.Get ("MyConstraint", empty) == Example: MyConstraint);
Comments
Post a Comment