+ InnerException {"Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'SCalcCA.Services.AccountService'."} System.Exception {System.InvalidOperationException} code example

Example 1: .net core System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' has been registered

services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

Example 2: No service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' has been registered

services.AddHttpContextAccessor();