Created
March 15, 2022 21:27
-
-
Save jsquire/99ccca6ac30a18c562c1943ea6272c5b to your computer and use it in GitHub Desktop.
Text Analytics Transparent Proxy Thoughts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the convenience layer that customers interact with. | |
// This should look almost exactly like the current API: | |
// https://apiview.dev/Assemblies/Review/2d2a87eaa70a43b8860f1c4e7135494b | |
// | |
// Because it isn't interacting with the swagger types, we probably need to clone the | |
// current implementation and use it as template. | |
// | |
public class TextAnalyticsClient | |
{ | |
TransportClient _transport = this.serviceVersion switch | |
{ | |
v3.0 => new LegacyTransportClient(), | |
v3.1 => new LegacyTransportclient(), | |
2022-03-01 => new LanguageTransportClient() | |
}; | |
public Task<DoAThing> SomeMethod(SomeType input) | |
{ | |
await _transport.SomeMethod(SomeType input); | |
} | |
} | |
// This is a neutral abstraction of the "second convenience" level. It | |
// exists just to make the convenience layer's life easier. | |
// | |
// This is based on types from the convenience layer and looks very | |
// similar to the 5.2.0 API. | |
// | |
internal abstract class TransportClient | |
{ | |
public abstract Task<DoAThing> SomeMethod(SomeType input); | |
} | |
// This is the thing that knows how to take the convenience layer types | |
// and translate them into the Legacy swagger format. This will look pretty | |
// similar to the legacy convenience layer. | |
// | |
internal class LegacyTransportClient | |
{ | |
public Task<DoAThing> SomeMethod(SomeType input) | |
{ | |
OldType oldType = TranslateSomeType(input); | |
OldThing oldResult = legacyRestClient.InvokeSomeMethod(oldType); | |
return TranslateToDoAThing(oldResult); | |
} | |
} | |
// This is the thing that knows how to take the convenience types | |
// and translate them into the Language swagger format. | |
// | |
// This looks like what a convenience layer would look like if we built one | |
// just for the new Language swagger. But in our case, we're using it internally | |
// rather than exposing it. | |
// | |
internal class LanguageTransportClient | |
{ | |
public Task<DoAThing> SomeMethod(SomeType input) | |
{ | |
NewType newType = TranslateSomeType(input); | |
NewThing newResult = languageRestClient.InvokeSomeMethod(newType); | |
return TranslateToDoAThing(newResult); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment