我正在使用ninject创建自定义成员资格提供程序以绑定到sql类。
我的班级看起来像
public MyMembershipProvider(IUsersRepository userRepository)
{
this.userRepository = userRepository;
}
如何从这个无参数构造函数创建?
答案 0 :(得分:2)
kernel.Bind<IUsersRepository>().To<UsersRepository>();
kernel.Bind<MembershipProvider>().To<MyMembershipProvider>();
然后:
public class AccountController : Controller
{
private readonly MembershipProvider _membershipProvider;
public AccountController(MembershipProvider membershipProvider)
{
_membershipProvider = membershipProvider;
}
public ActionResult Foo()
{
// TODO: Use the membership provider to do some processing
return View();
}
}