Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if Windsor has a matching component registered

In a Castle Windsor scenario I want to check if my container has a certain service registered, and do basically

if (container.HasComponentFor<IMyService>()) {
    // resolve service with container.Resolve<IMyService>()
    // then do cool stuff
}

but of course, container.HasComponentFor<IMyService>() doesn't exist. Is there an equivalent?

like image 764
Tomas Aschan Avatar asked Feb 06 '15 12:02

Tomas Aschan


2 Answers

You can check if the MicroKernel has the component registered:

if (container.Kernel.HasComponent(typeof(IMyService)))
    // resolve service with container.Resolve<IMyService>()
    // then do cool stuff
}
like image 137
Gareth Adams Avatar answered Oct 25 '22 16:10

Gareth Adams


You could try container.Kernel.HasComponent()

like image 36
Jessica Avatar answered Oct 25 '22 14:10

Jessica