I have an problem to declare dependency injection. I have to declare a WCF service and I did it like this:
services.AddTransient<IService, ServiceClient>();
As I will need to work with the WCF header I need to add a behavior to check the headers. Normally I would do it like this:
var client = new ServiceClient();
client.Endpoint.Behaviors.Add( new HeaderInspectionBehavior());
But I can't do it that way because I'm getting the IService
injected in the constructor.
I tried to do it this way:
var client = new ServiceClient();
client.Endpoint.Behaviors.Add(new HeaderInspectionBehavior());
services.AddTransient<IService, ServiceClient>(sp => client);
But it didn't work, in the second WCF call it changes the state to "FAULT" or "CLOSED".
Does anyone know of another way to do this?