1 回答

TA贡献1811条经验 获得超4个赞
当调用构造函数时,上下文尚不可用。
它将在调用预期函数时填充。
public class Basehub : Hub {
protected IUserProfileProvide userProfileProvider;
public Basehub(IUserProfileProvide userProfileProvider) {
this.userProfileProvider = userProfileProvider;
}
}
在流程中推迟对它的访问,就像在框架有时间正确填充上下文时的方法中一样。
public class NotificationHub: BaseHub {
public NotificationHub(IUserProfileProvide userProfileProvider)
: base(userProfileProvider) { }
public async Task InvokeMe(string message) {
IUserProfile profile = userProfileProvider.InitUserProfile(Context); //context populated
//...
await Clients.All.SendAsync("invoked",message);
}
}
- 1 回答
- 0 关注
- 175 浏览
添加回答
举报