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

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

                
                        services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();