title: How to use MassTransit InMemory?
body: <p>I want to register consumer <strong>by interface</strong>, send message, initialize it <strong>by interface</strong> from container, then consume:</p>
  <pre><code>public sealed class TestConsumer&lt;T&gt; : IConsumer&lt;T&gt;
      where T : class
  {
      private readonly Func&lt;ConsumeContext&lt;T&gt;, Task&gt; _onConsume;
      private readonly EventWaitHandle _handle;
      public TestConsumer(Func&lt;ConsumeContext&lt;T&gt;, Task&gt; onConsume)
      {
          _onConsume = onConsume;
          _handle = new EventWaitHandle(false, EventResetMode.ManualReset);
      }
  
      public async Task Consume(ConsumeContext&lt;T&gt; context)
      {
          try
          {
              await _onConsume(context).ConfigureAwait(false);
          }
          finally
          {
              _handle.Set();
          }
      }
  
      public async Task GetTask()
      {
          while (!_handle.WaitOne(0))
              await Task.Delay(100);
      }
  }
  
  
  public class MyRequest { }
  
  [TestFixture]
  public class ConsumerTests
  {
      [Test]
      public async Task Test()
      {
          var services = new ServiceCollection();
          var tc = new TestConsumer&lt;MyRequest&gt;(async (c) =&gt; Console.WriteLine(&quot;request&quot;));
          services.AddSingleton&lt;IConsumer&lt;MyRequest&gt;&gt;(tc);
          services.AddSingleton&lt;IBusControl&gt;(x =&gt; Bus.Factory.CreateUsingInMemory(cfg =&gt;
          {
              cfg.ReceiveEndpoint(&quot;foobar&quot;, c =&gt; { c.Consumer&lt;IConsumer&lt;MyRequest&gt;&gt;(x); });
          }));
  
          var sp = services.BuildServiceProvider();
  
          await sp.GetRequiredService&lt;IBusControl&gt;().StartAsync();
  
          //and how do I send it?
          //this will obviously not work with Uri!!!
          var sendEndpoint = await sp.GetRequiredService&lt;IBusControl&gt;().GetSendEndpoint(new Uri(&quot;foobar&quot;, UriKind.Relative));
          await sendEndpoint.Send(new MyRequest());
  
          await tc.GetTask();
          Console.WriteLine(&quot;done&quot;);
      }
  }
  </code></pre>
  <p>Honestly, lack of documentation is driving me crazy. There is such thing as harness, but it works only if you throw your DI container into garbage can or write a ton of adapters.</p>
  <p>How do one can use InMemory and combine it to completely uncompatible Uri in Send method?</p>