我的应用程序有问题。最近,我下载了Ninject软件包,但无法绑定我的实体。
我的控制器:
public class ServerController : ApiController
{
private readonly IServerService _service;
public ServerController(IServerService service)
{
this._service = service;
}
RegisterServices:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IServerService>().To<ServerService>().InSingletonScope();
kernel.Bind<IRepository<Server>>()
.To(typeof(ServerRepository))
.InRequestScope();
}
ServerService:
private readonly IRepository<Server> _repository;
public ServerService(IRepository<Server> repository)
{
this._repository = repository;
}
public async Task<IEnumerable<Server>> GetAllAsync()
{
return await this._repository.GetAllAsync();
}
如果有人需要更多信息,我会将其发送给评论。
答案 0 :(得分:0)
问题已解决。我刚刚向DAL模型添加了新接口并实现了IRepository。之后,我的Ninject寄存器如下所示:
kernel.Bind<IServerService>().To<ServerService>().InSingletonScope();
kernel.Bind<IServerRepository>().To<ServerRepository>().InSingletonScope();