Dependency Injection wcf

前端 未结 2 1024
天命终不由人
天命终不由人 2020-11-30 08:35

I want inject a implementation of my Interface in the WCF but I want initialize my container of Dependency Injection in the Client of the WCF. So I can have a different impl

2条回答
  •  醉酒成梦
    2020-11-30 08:53

    Here is what I understand from your question:

    You have an interface that is not related to WCF. Let's call it IInterface

    You have a WCF client that used a service. Let's call the service contract: IService

    you want the ServiceClient class that by default implements the IService when you add a service reference also to implement IInterface.

    IF this is the case, you can use the fact that the ServiceClient class is marked as partial.

    Just make another partial declaration for ServiceClient and add the interface you need (You have to make sure that the namespaces are equal for the auto-generated code and your code). It should look somthing like:

    namespace [ServiceClient Namespace]
    {
        public partial class ServiceClient : IInterface
        {
        }
    }
    

    Hope it helped.

提交回复
热议问题