title: Force an instance of class to use an interface
body: <p>How do I force <code>WebSocketClient</code>'s class instance to use the <code>IWebSocketClient</code> interface in its instantiation?</p>
  <p>For ex. I don't have <code>ConnectAsync</code> method listed in the interface and I expect the code to not allow me to call it.</p>
  <pre class="lang-cs prettyprint-override"><code>IWebSocketClient webSocketClient = new WebSocketClient(uri);
  await webSocketClient
      .ConnectAsync(CancellationToken.None) // ConnectAsync is missing which is expected behavior
      .ConfigureAwait(false);
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>var webSocketClient = new WebSocketClient(uri);
  await webSocketClient
      .ConnectAsync(CancellationToken.None) // it allows me to call it, which is not expected behavior
      .ConfigureAwait(false);
  </code></pre>
  <h2>Snippet</h2>
  <pre class="lang-cs prettyprint-override"><code>public interface IWebSocketClient : IDisposable
  {
      WebSocketState State { get; }
  }
  
  public class WebSocketClient : IWebSocketClient
  {
      public WebSocketClient(Uri uri)
      {
      }
  
      /// &lt;inheritdoc /&gt;
      public WebSocketState State =&gt; _webSocket.State;
  
      public async Task ConnectAsync(CancellationToken cancellationToken)
      {
          ...
      }
  }
  </code></pre>