views:

8

answers:

1

I want to remove dependencies from my classes for WCF Services. I want to inject them into the constructor as an interface and then mock the interface when I am testing that class.

What is the best practice and the fastest way for doing this?

my class:

class Test
{
public IMyWCFInterface _wcf;
 public Test(IMyWCFInterface wcf)
{
_wcf=wcf;
}
}
A: 

When you generate a WCF client proxy, an interface for the proxy should be generated for you. In addition, the generated client class that derives from ClientBase<TChannel> should implement that interface. Rather than depending on the class, depend on the interface, and inject an instance of the client class. That should resolve your problem.

jrista
jr, you seem to be echoing what the OP stated as his intentions yet provide no guidance ??
Sky Sanders
If he is already doing that, I'm not sure what more to offer. If a class depends on an interface, the interface can easily be mocked with a framework like Moq or RhinoMocks. Any IoC framework such as Castle Windsor, Ninject, etc. can inject instances of the client class.
jrista