Joe
Joe

Reputation: 735

How can I abstract three objects of the same type coming from three different services?

I am using a service with several endpoints divided out by their subsystem. All the systems have a set of standard objects that are used to pass structured data back and forth. In a given application, I am using three of the seven available end points. ServiceA, ServiceB and ServiceC. Establishing a connect to each returns a structure of EnvironmentVariableType, but because each comes back from a different service, C# considers them to be different types. ServiceA.EnvironmentVariableType, ServiceB.EnvironmentVariableType and ServiceC.EnvironmentVariableType.

Is there a way to abstract them and treat all three as the same object type?

Upvotes: 3

Views: 95

Answers (2)

Ian Mercer
Ian Mercer

Reputation: 39297

If you can't modify the generated code for the services to insert a common interface or to use the same types you could instead use Impromptu Interface which would allow you to take the result of each call and make it ActLike an interface you define. It's available in Nuget.

Upvotes: 1

Zara_me
Zara_me

Reputation: 268

You need to create adapter layer via interface. Derive your own classes from this interface and each class access one service which convert service objects or types to your application local types.

Upvotes: 1

Related Questions