title: How to add IHttpContextAccessor in the Startup class in the DI in ASP.NET Core 1.0?
body: <p>In ASP.NET Core RC 1 I used the following code to retrieve the value of context (full address of the page). Then I recorded this value in the configuration.</p>
  <pre><code>public class Startup
  {
          public IConfigurationRoot Configuration { get; set; }
          private IHostingEnvironment CurrentEnvironment { get; set; }
          private IHttpContextAccessor HttpContextAccessor { get; set; }
          public Startup(IHostingEnvironment env,
                  IHttpContextAccessor httpContextAccessor)
              {                
                  var builder = new ConfigurationBuilder()
                      .SetBasePath(env.ContentRootPath)
                      .AddJsonFile(&quot;appsettings.json&quot;, optional: true, reloadOnChange: true)
                      .AddJsonFile($&quot;appsettings.{env.EnvironmentName}.json&quot;, optional: true);
      
                  if (env.IsDevelopment())
                  {
                      builder.AddUserSecrets();
                  }
                  builder.AddEnvironmentVariables();
                  Configuration = builder.Build();
                  CurrentEnvironment = env;
                  HttpContextAccessor = httpContextAccessor;
              }
          public void ConfigureServices(IServiceCollection services)
          {
          ...
          
          services.AddOptions();
          services.Configure&lt;WebAppSettings&gt;(configuration);
          services.Configure&lt;WebAppSettings&gt;(settings =&gt;
          {
              ...
              settings.WebRootPath = CurrentEnvironment.WebRootPath;
              settings.DomainUrl = HttpContextAccessor.HttpContext.Request.Host.ToUriComponent();
          });
          }
     }
  </code></pre>
  <p>Now I started to update the project on ASP.NET Core 1.0. But during the launch of the site I get the following error:</p>
  <blockquote>
  <p>System.InvalidOperationException Unable to resolve service for type
  'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to
  activate 'MyProject.Startup'.</p>
  <p>at
  Microsoft.Extensions.Internal.ConstructorMatcher.CreateInstance(IServiceProvider
  provider)  at
  Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider
  provider, Type instanceType, Object[] parameters)  at
  Microsoft.Extensions.Internal.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider
  provider, Type type)  at
  Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider
  provider, Type type)  at
  Microsoft.AspNetCore.Hosting.Internal.StartupLoader.LoadMethods(IServiceProvider
  services, Type startupType, string environmentName)  at
  Microsoft.AspNetCore.Hosting.&lt;&gt;c__DisplayClass1_0.b__1(IServiceProvider
  sp)  at
  Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider
  provider)  at
  Microsoft.Extensions.DependencyInjection.ScopedCallSite.Invoke(ServiceProvider
  provider)  at
  Microsoft.Extensions.DependencyInjection.SingletonCallSite.Invoke(ServiceProvider
  provider)  at
  Microsoft.Extensions.DependencyInjection.&lt;&gt;c__DisplayClass12_0.b__0(ServiceProvider
  provider)  at
  Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type
  serviceType)  at
  Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider
  provider, Type serviceType)  at
  Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider
  provider)  at
  Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()  at
  Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
  at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()</p>
  <p>.NET Framework X64 v4.0.30319.42000   |   Microsoft.AspNetCore.Hosting
  version 1.0.0-rtm-21431   |   Microsoft Windows 6.1.7601 S</p>
  </blockquote>
  <p>How do I get the new version IHttpContextAccessor during application startup?</p>