title: asp.net core C# how can I pass value in a repository pattern
body: <p>I am new to C# and asp.net core and I am trying to create a simple repository pattern and pass a <code>string</code> value but I'm getting the error</p>
  
  <blockquote>
    <p>An unhandled exception occurred while processing the request.
    InvalidOperationException: Unable to resolve service for type 'HomepageRepository' while attempting to activate 'WebApplication.Controllers.HomeController'.
    GetService</p>
  </blockquote>
  
  <p>This is my code</p>
  
  <pre><code>public static class DBConnection 
  {
  
      public static string  connectDB(this string connectionString) 
      {
          return connectionString = "pass value of this string";
      }
   }
  </code></pre>
  
  <p><code>HomePageRepository</code>: I would like to pass the value of <code>connectionString</code> here</p>
  
  <pre><code>public class HomepageRepository : IHomepageRepository
  {
      private string connectionString;
  
      public HomepageRepository()
      {
          connectionString= connectionString.connectDB();
      }
  
      public string Streams()
      {
          return connectionString;
      }
  }
  </code></pre>
  
  <p>Then pass this to my controller like this</p>
  
  <pre><code>namespace WebApplication.Controllers
  {
      public class HomeController : Controller
      {
          public HomepageRepository _repository;
  
          public HomeController(HomepageRepository repository)
          {
              _repository = repository;
          }
  
          public string Streams()
          {
              _repository.Streams();
  
              return "hello";
          }
      }
  }
  </code></pre>
  
  <p>Again I am very new to C# and this code above gives only a runtime error . All I am trying to do is pass the <code>connectionString</code> value in <code>DBConnection</code> to <code>HomePageRepository</code> then pass it into a controller in <code>HomeController</code>. Any suggestions would be great.</p>