更新时间:2023-02-15 19:52:12
安装 Ninject.Web 来自软件包管理器控制台或NuGet。
版本是3.2.1
或
它将安装以下4个包 -
public interface IUserService
{
列表< string> GetUsers();
}
public class UserService:IUserService
{
public List< string> GetUsers()
{
返回新列表< string> {john,eric};
}
}
然后添加绑定到〜 /App_Start/NinjectWebCommon.cs
。
在页面后面的代码中,使用 [Inject]
属性注入属性。
I have a fair idea of using the Repository Pattern and have been attempting to "upgrade" our current way of creating ASP .Net websites. So i do the following
namespace BLL.Interfaces
{
interface IUser
{
List<User> GetAllUsers();
}
}
namespace BLL.Services
{
public class UserService : BLL.Interfaces.IUser
{
public List<User> GetUsers()
{
throw new NotImplementedException();
}
}
}
I know the code is not fully completed, but there for illustrative purposes.
So i right click the BLL project > Manage NuGet Packages > Searched for Ninject and found a few. I was overwhelmed with the number of entries returned after after further research i am lost in how to add Ninject to a normal ASP .Net website? Specifically which addin i require? As there are many MVC and reading further i think im a little confused.
I was trying to add it to the BLL project as thats where i THINK it should go so i can register my services in there.
Could anyone guide me in what i need to so in order to use Ninject entries but im not using MVC?
Install Ninject.Web either from "Package Manager Console" or NuGet.
Version is 3.2.1 as of this writing.
OR
It will install the following 4 packages -
public interface IUserService
{
List<string> GetUsers();
}
public class UserService : IUserService
{
public List<string> GetUsers()
{
return new List<string> {"john", "eric"};
}
}
Then add binding to ~/App_Start/NinjectWebCommon.cs
.
In code behind page, property inject using [Inject]
attribute.