Having read and googled to the point of exhaustion, I feel as though I may need some guidance.
This may partly be because of the introduction of Castle Windsor 3.0, however most of the blog posts, SO questions and other documentation is explicitly dependant on what I can see is now deprecated code.
So: The problem?
In my application, which is a WCF Service providing back end code to an MVC3 application, I have multiple layers, one of which provides virus scanning services for a file upload system.
The client has asked for support for multiple scan services, naturally I have complied and each scan service implements an IScanService interface, thusly:
public interface IScanService
{
void Execute();
ScanResult GetResult();
}
So in the WCf service, where the constructor may look like:
public McAfeeFileScanService(IScanService mcAfeeScanService)
{
_scanService = scanService;
}
How can I specialise that the IScanService which is injected is of implementation type McAfeeScanService, or NortonScanService or other implementation?
AFAIK Windsor by default would provide the first registered implementation, whether that is of type McAfeeScanService or not.
I was looking into ServiceOverrides, however that seems to have been deprecated in Windsor 3.0 in favour of the DependsOn(Dependency.OnComponenent()) [but I have failed to find any relevant examples] Ive also looked into Typed Factory Facilities, and into IHandlerSelector, but feel that some guidance is needed for this (seemingly common and probably simple) task.
Thanks all.
ServiceOverride is deprecated in Windsor 3. You have to use Dependency.OnComponent like this:
Component.For<ISerializer>().ImplementedBy<JsonSerializer>().Named("jsonSerializer"),
Component.For<WebConnectionAcceptor, IChannelManager>().ImplementedBy<WebConnectionAcceptor>().Named("webAcceptor"),
Component.For<ConnectionAcceptorProxy>().Named("webProxy").DependsOn(
Dependency.OnComponent("connectionAcceptor", "webAcceptor"),
Dependency.OnComponent("serializer", "jsonSerializer"))
First argument in OnComponent is binding name, second is component name.
Take a look at the second example on the castle Windsor wiki at http://docs.castleproject.org/Default.aspx?Page=Inline-Dependencies&NS=Windsor&AspxAutoDetectCookieSupport=1
It think it is what you are looking for :)
container.Register( Component.For().ImplementedBy() .DependsOn(ServiceOverride.ForKey("Logger").Eq("secureLogger")) );
Regards
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