c# - How to coerce using direct class structuremap -
i have problem writing valid configuration classes. suppose have:
interface ia{} class abstract : ia {} class a1 : a, ia { private readonly ib _ib; public a1(ib ib) { _ib = ib; } } class a2 : a, ia { private readonly ib _ib; public a1(ib ib) { _ib = ib; } }
and want inject classes constructor of others, , think there have no problems that, doing this:
for<ienumerable<ia>>.use(x => x.allinstances<a>());
but don't know resolve problem property ib, if want use different _ib class a1 , class a2.
interface b{} class b1 : b {} class b2 : b {}
i know if have 1 class b , class can this:
for<ia>().use<asample>().ctor<ib>().is<bsample>();
but problem try use this:
for<ia>().conditionallyuse(c => { c.if(t => t.concretetype == typeof(a1)) .thenit .is.constructedby(by => new a1(by.instanceof<b1>())); c.if(t => t.concretetype == typeof(a1)) .thenit .is.constructedby(by => new a2(by.instanceof<b2>())); });
but gives me error of bidirectional registration..
or maybe should think this:
for<ienumerable<ia>>.use(x => x.allinstances<a>()); for<ienumerable<ib>>.use(x => x.allinstances<b>());
but variant should create abstract class, , additional method use 1 injected property list (for classes inherit interface b).
if me appreciate!
resolution problem write that:
for<ia>().add<a1>().ctor<ib>().is<b1>(); for<ia>().add<a2>().ctor<ib>().is<b2>(); //and for<ienumerable<ia>>.use(x => x.getallinstances<ia>());
Comments
Post a Comment