title: An unhandled exception occurred while processing the request- ASP .NET Core
body: <p>I'm new to ASP .net core. It giving me an dependency injection error as:</p>
  
  <blockquote>
    <p>InvalidOperationException: Unable to resolve service for type 'Spinit.Data.Services.Repository.GameRepository' while attempting to activate 'SpinIt.Web.Controllers.CartController'. Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)</p>
  </blockquote>
  
  <p>StackTrace is below:</p>
  
  <pre><code>Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
  lambda_method(Closure , IServiceProvider , object[] )
  Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider+&lt;&gt;c__DisplayClass4_0.&lt;CreateActivator&gt;b__0(ControllerContext controllerContext)
  Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider+&lt;&gt;c__DisplayClass5_0.&lt;CreateControllerFactory&gt;g__CreateController|0(ControllerContext controllerContext)
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
  Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
  Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
  Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
  Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
  Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  
  <p><em>CartController</em> Code</p>
  
  <pre><code>public class CartController:Controller
  {
      private readonly GameRepository _gameRepository;
      private readonly Cart _cartRepository;
  
      public CartController(GameRepository gameRepository, Cart cartRepository)
      {
          _gameRepository = gameRepository;
          _cartRepository = cartRepository;
      }
  
      public ViewResult Index()
      {
          var items = _cartRepository.GetCartItems();
          _cartRepository.CartItems = items;
  
          var sCVM = new CartViewModel
          {
              Cart = _cartRepository,
              CartTotal = _cartRepository.GetCartTotal()
          };
          return View(sCVM);
      }
  }
  </code></pre>
  
  <p>I have also add service to <em>Startup.cs</em></p>
  
  <pre><code>services.AddScoped&lt;IGame, GameRepository&gt;();
  services.AddScoped&lt;ICartItem, CartItemRepository&gt;();
  </code></pre>