我正在尝试创建一个CustomAuthUserSession,并使用RefIdStr属性将我自己的User文档与UserAuth对象相关联。
在我的CustomUserAuthSession的OnAuthenticated方法中,我正在执行以下操作
这是方法
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
var documentSession = authService.TryResolve<IDocumentSession>();
//get userAuth from raven
//var userAuth = documentSession.Load<UserAuth>(session.UserAuthId); //should this work?
var userAuthRepo = authService.ResolveService<IUserAuthRepository>();
var userAuth = userAuthRepo.GetUserAuth(session.UserAuthId);
if (userAuth.RefIdStr == null)
{
//need to create new User and save to Raven
var newUser = new User()
{
UserName = session.UserName,
Email = session.Email,
//Other properties...
};
documentSession.Store(newUser);
this.UserID = newUser.Id; //UserId property on custom session
userAuth.RefIdStr = newUser.Id;
userAuthRepo.SaveUserAuth(userAuth); //getting error here...
}
else
{
//get User from raven
var user = documentSession.Load<User>(userAuth.RefIdStr);
this.UserID = user.Id;
}
}
当我到达SaveUserAuth方法时,我收到以下错误...
Attempted to associate a different object with id 'UserAuths/12345'.
以下是我如何设置文档存储和IOC ......
//Set up RavenDB
var ravenStore = new DocumentStore()
{
ConnectionStringName = "RavenDB"
}.Initialize();
IndexCreation.CreateIndexes(typeof(RavenUserAuthRepository).Assembly, ravenStore);
container.Register(ravenStore);
container.Register(c => c.Resolve<IDocumentStore>().OpenSession()).ReusedWithin(ReuseScope.Request);
以及我如何配置我的auth repo ....
//register auth repository
container.Register<IUserAuthRepository>(p => new RavenUserAuthRepository(p.Resolve<IDocumentStore>(), p.Resolve<IDocumentSession>()));
var authRepo = (RavenUserAuthRepository)container.Resolve<IUserAuthRepository>();
为什么会出现此错误?
修改
只是为了澄清......我的意图是以与socialbootstrapapi项目类似的方式工作。
编辑2
根据以下评论,我已将IUserAuthRepository的Funq注册更改为:
container.Register<IUserAuthRepository>(p => new RavenUserAuthRepository(p.Resolve<IDocumentStore>(), p.Resolve<IDocumentSession>())).ReusedWithin(ReuseScope.Request);
但我仍然得到同样的错误......
答案 0 :(得分:1)
似乎更新到最新版本的SS已经解决了这个问题。不确定哪些更改解决了问题,但一切都按预期工作。