Windsor use one lifestyle if another fails.
-
I'd like to implement a container that looks under a bound lifestyle and failing finding the parent type uses another lifestyle instead.
Problem is that if I implement the transient as a fallback, windsor throws an exception if it can't find the boundto type in the component model hierarchy.
My original idea was this.
container.Register(Component.For<IThing>() .ImplementedBy<Thing>() .IsFallback() .LifestyleTransient()); container.Register(Component.For<IThing>() .ImplementedBy<BoundThing>() .LifestyleBoundTo<BindingParent>());
Nope, it just crashes... when it can't find BindingParent in the component model heirarchy
-
WTF is Windsor?
Other than that....
-
@Tsaukpaetra said in Windsor use one lifestyle if another fails.:
WTF is Windsor?
Other than that....
IOC.
I came up with a way to do it, but it involved complete custom lifestyle that involved custom lifestyleboundto method that capured BindingParent if it could find it, and returned the top level parent if it couldn't, then a custom lifestyle that returned BindingParent's instance if the context was BindingParent, and a new instance if not.
It's beastly code, but it works.
-
I tend to use AutoFac myself. There are quite a few alternatives that are pretty similar.
-
@sweaty_gammon said in Windsor use one lifestyle if another fails.:
AutoFac
I assume that's a PKD reference?