我用用于其他解决方案的代码创建一个ASP.NET Web API项目。
我安装了Ninject和Ninject.Extensions.ChildKernel软件包,但是在文件NinjectResolver.cs中找不到
代码:
using Ninject;
using Ninject.Extensions.ChildKernel;
using Assurance.Abstract;
using Assurance.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Dependencies;
namespace Assurance.API
{
public class NinjectResolver : IDependencyResolver
{
private IKernel kernel;
public NinjectResolver()
: this(new StandardKernel())
{
}
public NinjectResolver(IKernel ninjectKernel, bool scope = false)
{
kernel = ninjectKernel;
if (!scope)
{
AddBindings(kernel);
}
}
public IDependencyScope BeginScope()
{
return new NinjectResolver(AddRequestBindings(new ChildKernel(kernel)), true);
}
public object GetService(Type serviceType)
{
return kernel.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
return kernel.GetAll(serviceType);
}
public void Dispose()
{
}
private void AddBindings(IKernel kernel)
{
// singleton and transient bindings go here
}
private IKernel AddRequestBindings(IKernel kernel)
{
kernel.Bind(typeof(IClientRepository<>)).To(typeof(ClientRepository<>)).InSingletonScope();
kernel.Bind<IClientService>().To<ClientService>().InSingletonScope();
return kernel;
}
}
}
Ps:用于工作的代码,我成功安装了始终无法构建的软件包。
我该怎么办?