我正在使用带有MVC 6的Web API,这里我是为了将存储库注入控制器,我们需要将它注册到DI容器.打开Startup.cs文件.
在ConfigureServices方法中,将添加突出显示的代码:
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Owin; using Owin; using TodoApi.Models; [assembly: OwinStartup(typeof(TodoApi.Startup))] namespace TodoApi { public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Add our repository type services.AddSingleton<ITodoRepository,TodoRepository>(); } } }
The type or namespace name ‘IServiceCollection’ could not be found (are you missing a using directive or an assembly reference?)