title: What Ninject convention should I use to bind all interfaces starting with "I" with interfaces having the same name without the "I" prefix for COMObj?
body: <p>I'm working on integrating an accounting system which objects are COM objects.</p>
  <p>When binding one to one as follows, it works just fine.</p>
  <pre><code>IKernel kernel = new StandardKernel();
  kernel.Bind&lt;IAcoSDKX&gt;().ToMethod(_ =&gt; { return new AcoSDKX(); }).InSingletonScope();
  </code></pre>
  <p>The situation I'm having is that both <code>IAcoSDKX</code> and <code>AcoSDKX</code> are interfaces, and the <code>AcoSDKClass</code> is inaccessible to the consumer.</p>
  <p>So I'm looking for a way to bind both interfaces together as only their spelling differ.  Ont starts with an 'I', and other doesn't.  So I'd like to come up with a conventional binding where even though I keep using unbound interfaces, Ninject knows what to bind it to when activating the objects through constructor injection.</p>
  <p>Here's the try I came up with so far with no success.</p>
  <pre><code>kernel.Bind(services =&gt; services
        .FromAssembliesMatching(&quot;AcoSDK.dll&quot;)
        .SelectAllTypes()
        .Where(t =&gt; t.Name.StartsWith(&quot;I&quot;) &amp;&amp; t.IsInterface)
        .BindDefaultInterfaces());
  </code></pre>
  <p>So I wonder, how to configure a convention binding using Ninject that could suit the actual need?</p>
  <p>Basically the convention is to bind all interfaces starting with &quot;I&quot; with interfaces having the same name without the &quot;I&quot; prefix.</p>
  <blockquote>
  <p>EDIT</p>
  </blockquote>
  <p>After further searches, I found out that the types of AcoSDK.dll are embedded into my own assembly.  Only types that are early loaded are bindable.</p>
  <p>Besides, although I can new a COM Object interface, the <em>Activator.CreateInstance</em> won't initialize it under pretext that it is an interface.  See objects declaration as follows:</p>
  <pre><code>namespace AcoSDK {
      [ComImport]
      [Guid(&quot;00000114-0000-000F-1000-000AC0BA1001&quot;]
      [TypeLibType(4160)]
      public interface IAcoSDKX { }
  
      [ComImport]
      [Guid(&quot;00000114-0000-000F-1000-000AC0BA1001&quot;)]
      [CoClass(typeof(AcoSDKClass))]
      public interface AcoSDKX : IAcoSDKX { }
  
      [ComImport]
      [Guid(&quot;00000115-0000-000F-1000-000AC0BA1001&quot;)]
      [TypeLibType(2)]
      [ClassInterface(0)]
      public class AcoSDKXClass : IAcoSDKX, AcoSDKX { }
  }
  
  public class Program() {
      // This initializes the type.
      IAcoSDKX sdk = new AcoSDKX();  
      
      // This also does.
      IKernel kernel = new StandardKernel();
      kernel.Bind&lt;IAcoSDKX&gt;().ToMethod(_ =&gt; new AcoSDKX()); 
  
      // This won't activate because type is an interface.
      IAcoSDKX sdk = Activator.CreateInstance(typeof(AcoSDKX));  
  
      //  This says :  Interop type AcoSDKXClass cannot be embedded.  Use the applicable interface instead.    
      IAcoSDKX sdk = Activator.CreateInstance(typeof(AcoSDKXClass));  
  
      // Same message occurs when newing.
      IAcoSDKX sdk = new AcoSDKClass();  
  }
  </code></pre>
  <p>Given this new information, anyone has a similar experience with COM Objects?  I tried to new the <code>AcoSDKClass</code> or to access it in any fashion, and I just don't seem to get a hook on it.</p>