I have some existing interfaces that are used over all over system.
Now I want to use one of the interfaces to be as service contract.
But the problem is that I need to add [ServiceContract] and [OperationContract] attributes on existing interfaces and they will contaminate the rest of the code .
Any solution to this problem with out duplicating the interfaces?
Applying the attributes on the concrete implementation ? is that a good practice ?
Thanks
You could simply extend the interface with a service-warpper type interface, i.e.:
C# allows interface inheritance, and the compiler will spit out a warning that
IMyCodeService.GetResultrequires new because it hides theIMyCode.GetResultmethod, but not appendingnewwill not break the implementation, as an example:That way, you can provide a service contract based on your existing interface without changing your existing code.
If you share your contract assembly instead of using WCF to generate a proxy for you, you can even pass your service contract in places where you’d accept your existing interface, because the service interface inherits from it.