When resolving a component which the Windsor container cannot find, an exception is thrown.
StructureMap has a TryGetInstance method, which returns null of it can't find the requested component.
Does Castle Windsor has something like this? Or am I forced to catch these exceptions (I don't like that, because of the performance overhead of throwing and catching exceptions).
Thanks in advance,
Remco
You can check if the MicroKernel has an instance of the component registered before calling the Resolve method of the Windsor container.
Something like the following should work.
if ( windsor.Kernel.HasComponent( componentType ) )
{
return windsor.Resolve( componentType );
}
return null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With