No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered

前端 未结 11 812
终归单人心
终归单人心 2021-01-01 08:57

I\'m having this problem: No service for type \'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory\' has been registered. In asp.net core 1.0,

11条回答
  •  感动是毒
    2021-01-01 09:29

    For those that get this issue during .NetCore 1.X -> 2.0 upgrade, update both your Program.cs and Startup.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }
    
        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup()
                .Build();
    }
    
    public class Startup
    {
    // The appsettings.json settings that get passed in as Configuration depends on 
    // project properties->Debug-->Enviroment Variables-->ASPNETCORE_ENVIRONMENT
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
    
        public IConfiguration Configuration { get; }
    
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    
            services.AddIdentity()
                .AddEntityFrameworkStores()
                .AddDefaultTokenProviders();
    
            services.AddTransient();
    
            services.AddMvc();
        }
    
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
        // no change to this method leave yours how it is
        }
    }
    

提交回复
热议问题