如何使用 Ninjects 将服务注入到自制的 RoleProvider 类中?
在实现 Roleprovider 时,以便它从数据库获取角色。我不断得到一个对象,没有...异常的实例。
事实证明 ninject 没有注入我的服务。
我尝试将属性放在属性之上,但没有成功。 我尝试添加一个构造函数,但随后出现黄屏死机,告诉我应该有一个无参数构造函数
代码是
Public Class AnipRolProvider
Inherits RoleProvider
'this service needs to get initialized
Private _memberhip As IMemberschipService
Sub New()
'only this constructor is called by asp by default
End Sub
Sub New(memberschipservice As IMemberschipService)
'this constructor should be called but how ?
_memberhip = memberschipservice
End Sub
我需要的唯一方法
Public Overrides Function GetRolesForUser(username As String) As String()
If String.IsNullOrEmpty(username) Then
Throw New ArgumentException("username is nothing or empty.", "username")
End If
Return _memberhip.GetRolesForUser(username)
End Function
如何实现 ninjects 以便角色提供者与忍者合作?
附加信息:
<roleManager enabled="true" defaultProvider="AnipRoleProvider">
<providers>
<clear/>
<add name="AnipRoleProvider" type="Anip.Core.AnipRolProvider" />
</providers>
</roleManager>
在我的 web.config 中有对aniproleprovider的引用。
offtopic-sidenote:在复制这些片段集时,我应该学会写更好的名字!
While implementing the Roleprovider so that it gets the roles from a database. I keep getting a object no instance of... exception.
As it turns out ninject does not inject my service .
I tried putting the attribuut on top of the property no succes.
I tried adding a constructor but then im getting a yellow screen of death telling me there should be a parameterless constructor
The code
Public Class AnipRolProvider
Inherits RoleProvider
'this service needs to get initialized
Private _memberhip As IMemberschipService
Sub New()
'only this constructor is called by asp by default
End Sub
Sub New(memberschipservice As IMemberschipService)
'this constructor should be called but how ?
_memberhip = memberschipservice
End Sub
the only method i need
Public Overrides Function GetRolesForUser(username As String) As String()
If String.IsNullOrEmpty(username) Then
Throw New ArgumentException("username is nothing or empty.", "username")
End If
Return _memberhip.GetRolesForUser(username)
End Function
How do i implement ninjects so that role provider team up with the ninja?
Additional information :
<roleManager enabled="true" defaultProvider="AnipRoleProvider">
<providers>
<clear/>
<add name="AnipRoleProvider" type="Anip.Core.AnipRolProvider" />
</providers>
</roleManager>
in my web.config there is a reference to aniproleprovider.
offtopic-sidenote : while copying these snipsets i should learn to write better names!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在 global.ascx 中注册您的 IMembershipService,不知道如何在 VB 中执行此操作,将其放入 C# 中,如下所示:
You have to register your IMembershipService in the global.ascx, don't know how to do this in VB put in c# it looks like this :