Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extend ServiceStack UserAuth using RefIdStr and RavenDB
    text
    copied!<p>I am attempting to create a CustomAuthUserSession along with associating my own User document with the UserAuth object using the RefIdStr property.</p> <p>In the OnAuthenticated method of my CustomUserAuthSession I am doing the following</p> <ol> <li>getting the userAuth object by the UserAuthId on the session</li> <li>creating an instance of IDocumentSession for Raven</li> <li>creating a new instance of User and calling Store on my document session</li> <li>updating the RefIdStr on userAuth</li> <li>calling SaveUserAuth on my userauth repo</li> </ol> <p>here is the method</p> <pre><code>public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary&lt;string, string&gt; authInfo) { base.OnAuthenticated(authService, session, tokens, authInfo); var documentSession = authService.TryResolve&lt;IDocumentSession&gt;(); //get userAuth from raven //var userAuth = documentSession.Load&lt;UserAuth&gt;(session.UserAuthId); //should this work? var userAuthRepo = authService.ResolveService&lt;IUserAuthRepository&gt;(); 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&lt;User&gt;(userAuth.RefIdStr); this.UserID = user.Id; } } </code></pre> <p>When I get to the SaveUserAuth method, I am getting the following error...</p> <p><code>Attempted to associate a different object with id 'UserAuths/12345'.</code></p> <p>Here is how I am setting up my document store and IOC...</p> <pre><code>//Set up RavenDB var ravenStore = new DocumentStore() { ConnectionStringName = "RavenDB" }.Initialize(); IndexCreation.CreateIndexes(typeof(RavenUserAuthRepository).Assembly, ravenStore); container.Register(ravenStore); container.Register(c =&gt; c.Resolve&lt;IDocumentStore&gt;().OpenSession()).ReusedWithin(ReuseScope.Request); </code></pre> <p>and how I configure my auth repo....</p> <pre><code>//register auth repository container.Register&lt;IUserAuthRepository&gt;(p =&gt; new RavenUserAuthRepository(p.Resolve&lt;IDocumentStore&gt;(), p.Resolve&lt;IDocumentSession&gt;())); var authRepo = (RavenUserAuthRepository)container.Resolve&lt;IUserAuthRepository&gt;(); </code></pre> <p>Any ideas why this error would occur? </p> <p><strong>EDIT</strong></p> <p>Just to clarify...my intention is for this to work in a similar fashion as the socialbootstrapapi project. </p> <p><strong>EDIT 2</strong></p> <p>Per the comments below, I have changed the Funq registration of IUserAuthRepository to:</p> <pre><code>container.Register&lt;IUserAuthRepository&gt;(p =&gt; new RavenUserAuthRepository(p.Resolve&lt;IDocumentStore&gt;(), p.Resolve&lt;IDocumentSession&gt;())).ReusedWithin(ReuseScope.Request); </code></pre> <p>But I am still getting the same error...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload