title: .blazor dependency injection error: An unhandled exception occurred while processing the request.?
body: <p>Using SqlSugar ORM, based on blazor, dependency injection business service, an error is reported when calling。
  SqlSugarService：</p>
  <pre><code> public static class SqlSugarService
      {
          private static readonly ILog log = LogManager.GetLogger(typeof(SqlSugarService));
          public static void AddSqlSugarSevice(this IServiceCollection services)
          {
              if (services == null) throw new ArgumentNullException(nameof(services));
          
              services.AddScoped&lt;ISqlSugarClient&gt;(o =&gt;
              {
              
                  var listConfig = new List&lt;ConnectionConfig&gt;();
                  listConfig.Add(new ConnectionConfig
                  {
                      DbType = DbType.SqlServer,
                      ConnectionString = &quot;Server=.\\SQLEXPRESS;DataBase=Test;Uid=sa;Pwd=123456&quot;,
                      IsAutoCloseConnection = true,
                      InitKeyType = InitKeyType.Attribute
                  });
                  var dbContext = new SqlSugarClient(listConfig);
                  
                  return dbContext;
                 
              });
  
          }
  
      }
  </code></pre>
  <p>the interface：</p>
  <pre><code>  public interface IReportRepository
      {
            public DataTable GetTest(string sql);
      }
  </code></pre>
  <p>Interface implementation：</p>
  <pre><code> public class ReportRepository : IReportRepository
      {
          private ISqlSugarClient _dbBase;
          public ReportRepository(ISqlSugarClient sqlSugar)
          {
               _dbBase = sqlSugar;
           }
      
          
          public DataTable GetTest(string sql)
          {
            return _dbBase.Ado.GetDataTable(sql);
          }
  
  }
  </code></pre>
  <p>injection：</p>
  <pre><code>  services.AddSqlSugarSevice();
    services.TryAddTransient&lt;IReportRepository, ReportRepository&gt;(); 
  </code></pre>
  <p>use constructor injection：</p>
  <pre><code>   private readonly IReportRepository _reportRepository;
  
          //[Inject]
          //public IReportRepository ReportService { get; set; }
  
          public Report(IReportRepository  reportRepository)
          {
              _reportRepository = reportRepository;
              _reportRepository.GetTest(&quot;select * from test&quot;);
          }
  </code></pre>
  <p><strong>ERROR :</strong></p>
  <blockquote>
  <p>An unhandled exception occurred while processing the request.
  MissingMethodException: No parameterless constructor defined for type 'MyReport.Pages.Report'.
  System.RuntimeType.CreateInstanceDefaultCtorSlow(bool publicOnly, bool wrapExceptions, bool fillCache)</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/85Lws.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/85Lws.png" alt="enter image description here" /></a></p>
  <blockquote>
  <pre><code>public partial class Report
  {
      private readonly IReportRepository _reportRepository;
  
      //[Inject]
      //public IReportRepository ReportService { get; set; }
      public Report()
      {
          
      }
      public Report(IReportRepository  reportRepository)
      {
          _reportRepository = reportRepository;
          _reportRepository.GetTest(&quot;select * from test&quot;);
      }
  
  
  }
  </code></pre>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/Gf9NH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gf9NH.png" alt="enter image description here" /></a></p>