Castle optional(property) dependency problem, in realtion with Typed Factory facility -
i'm facing following problem
given pseudo code,
public interface ia { ... } public interface ib { ia someoptionaldependency; } public interface irepositorya { ... ia getdefault(); ia get(object id); } public interface ifactoryb { ib create(); ib create(ia a); } public class b : ib { public b(irepositorya repoa) { _repoa=repoa; } public ia someoptionaldependency { get{ if (_someoptionaldependency==null) _someoptionaldependency=_repoa.getdefault(); return _someoptionaldependency; } set{ if (_someoptionaldependency!=null) throw(new exception("this read only"); _someoptionaldependency=value; } } private ia _someoptionaldependency; private irepositorya _repoa; } [testfixture] public class test { [test] public void factorymethodsshouldwork() { var factoryb=container.resolve<ifactoryb>(); var repoa=container.resolve<irepositorya>(); var somea=repoa.get(someid); var b1=factoryb.create(); var b2=factoryb.create(somea); assert.areequal(repoa.getdefault(),b1.someoptionaldependency); assert.areequal(somea,b1.someoptionaldependency); } }
i'm using typed factory facility factory, , registering container. test don't pass, because containter resolve optional dependency of , put new object on it, someoptionaldependency never null; here tricky thing, if setup dependency [donotwire], not resolve it(obviously) in case, both factory methods, sort of need windsor resolve named args factory facility injects in resolving pipeline , not typed resolving. there way configure or extend windsor this. missing point here? can work around doing factory wrapper set value , setting [donotwire], have problem in several factories, , seems should way work in more proper way
thanks in advance
Comments
Post a Comment