title: DI Exception in ASP.NET Core: Could not create an instance of type 'MyProject.Data.ITableRepositories'
body: <p>I try to follow the article <a href="http://www.dotnetcurry.com/visualstudio/1328/visual-studio-connected-services-aspnet-core-azure-storage" rel="nofollow noreferrer">Access Azure Storage in an ASP.NET Core application using Connected Services</a>, under ASP.NET Core 1.1 in order to connect my web application to Azure Tables. </p>
  
  <p>But the problem is that under ASP.NET Core and <code>Microsoft.WindowsAzure.Storage</code> nuget I have no acces to the Syncronous methods. </p>
  
  <p>I am a beginner with async programming, so probably the code bellow is a little bit crazy, however this is my version of the "Async Azure Connector":   </p>
  
  <pre><code>// Model
  public class Record : TableEntity {
      public Record() { }
      public Record(string id, string name, string partition = "record") {
          this.RowKey = id;
          this.PartitionKey = partition;
          this.Name = name;
      }
      [...]
  }    
  
  // Data Interface
  public interface ITableRepositories {
      Task&lt;bool&gt; CreateRecordAsync(Record record);
      Task&lt;List&lt;Record&gt;&gt; GetRecordsAsync();
      Task&lt;Record&gt; GetRecordAsync(string key, string partitionKey = "record");
  }
  
  // Data Class
  public class TableClientOperationsService : ITableRepositories {
      private string connectionString;
      private CloudTable recordTable;
  
      public TableClientOperationsService() { }
      public TableClientOperationsService(IOptions&lt;AppSecrets&gt; optionsAccessor) {
          connectionString = optionsAccessor.Value.MyProjectTablesConnectionString;
      }
  
      public CloudTable RecordTable {
          get {
              if (recordTable == null) {
                  recordTable = GetTable("Record");
              }
              return recordTable;
          }
      }
  
      private CloudTable GetTable(string tableName) {
          [.connectionString.]
          table.CreateIfNotExistsAsync().Wait();
          return table;
      }
  
      public async Task&lt;T&gt; Get&lt;T&gt;(string partitionKey, string rowKey, string tableName) where T : ITableEntity, new()
      {            [...]        }
  
      public async Task&lt;bool&gt; CreateRecordAsync(Record record) {
          TableOperation insertOperation = TableOperation.Insert(record);
          await this.RecordTable.ExecuteAsync(insertOperation);
          return true;
      }
  
      public async Task&lt;Record&gt; GetRecordAsync(string key, string partitionKey = "record") {
          const string TableName = "Record";
          Record myRecord = await Get&lt;Record&gt;(partitionKey, key, TableName);
          return myRecord;
      }
  
      public async Task&lt;List&lt;Record&gt;&gt; GetRecordsAsync() {
          TableQuery&lt;Record&gt; recordsQuery = new TableQuery&lt;Record&gt;().Where(
              TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "record"));
          EntityResolver&lt;Record&gt; recordResolver = null;
          List&lt;Record&gt; myList = new List&lt;Record&gt;();
          TableQuerySegment&lt;Record&gt; currentSegment = null;
          while (currentSegment == null || currentSegment.ContinuationToken != null) {
              currentSegment = await recordTable.ExecuteQuerySegmentedAsync(
                  recordsQuery,
                  recordResolver,
                  currentSegment != null ? currentSegment.ContinuationToken : null);
  
              myList.AddRange(currentSegment.Results);
          }
          return myList;
      }
  }
  
  // Setup.cs configuration
  public void ConfigureServices(IServiceCollection services)
  {
      services.AddOptions();
      services.Configure&lt;AppSecrets&gt;(Configuration);
  
      // association of ITableRepositories with TableClientOperationsService
      services.AddSingleton(typeof(ITableRepositories), typeof(TableClientOperationsService));
  
      services.AddMvc();        
  }
  
  
  // Usage in the Controller
  public class HelloWorldController : Controller {
      public async Task&lt;string&gt; ReadTables1(ITableRepositories repository) {
          StringBuilder response = new StringBuilder();
          response.AppendLine("Here is your Record Table:");
          var items = await repository.GetRecordsAsync();
          foreach (Record item in items) {
              response.AppendLine($"RowKey: {item.RowKey}; Name: {item.Name}");
          }
          return response.ToString();
      }    
  </code></pre>
  
  <p>However, when I try to acces the controller action via <code>/HelloWorld/ReadTables1</code> 
  it trows me the following:</p>
  
  <blockquote>
    <p>InvalidOperationException: Could not create an instance of type 'MyProject.Data.ITableRepositories'. Model bound complex types must not be abstract or value types and must have a parameterless constructor.    </p>
  </blockquote>
  
  <p>Probably I registered it incorrectly in the services, because my TableClientOperationsService class is not abstract and has a parameter less constructor? How to fix it? </p>