views:

245

answers:

1

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

+2  A: 

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;
jweber
Yes, but it doesn't have an overload to Resolve by name AND type.only one for name and one for Type.
Remco Ros