Configuring my client app to use my CSLA 2.0 objects

Configuring my client app to use my CSLA 2.0 objects

Old forum URL: forums.lhotka.net/forums/t/401.aspx


Norma_B posted on Sunday, June 18, 2006

I'm very new to VS.NET, and am monumentally confused how to configure my client application to use my CSLA 2.0 business objects. I'm okay with setting the references (I'm including both CSLA and my business objects), but I get confused trying to:

1) ensure my custom principal and identity objects are used

2) ensure that the data access runs locally

I tried making a post with more detail, but it got pretty deep. (And rather pathetic. ;) ) I hope this is sufficient. Thanks!

bcdennis replied on Sunday, June 18, 2006

Norma,
Both those things are addressed & covered in explicit detail in Rocky's book.  (Chapter 4, i think.)

Norma_B replied on Monday, June 19, 2006

After a good night's sleep and a quick review of the code, I found my problem. We store user information keyed on their network login. I was using My.User.Name to get that info at runtime, but when I switched to Application-Defined authentication, My.User no longer contained the network credentials -- thus no match was being found. I've inserted a call to My.User.InitializeWithWindowsUser() before I initialize my custom Principal object, and we'll see how it works so far.

Norma_B replied on Monday, June 19, 2006

I also learned that one should not use a BackgroundWorker component to run the CustomPrincipal.Initialize event... the Principal ends up attached to the wrong thread. Sigh. Guess I will have to defeat the Splash screen in single combat after all.

ajj3085 replied on Monday, June 19, 2006

FWIW, you can attach the principal to the foreground thread as well.  Nothing wrong with that, and its a simple statement.

Andy

Norma_B replied on Monday, June 19, 2006

ajj3085:
FWIW, you can attach the principal to the foreground thread as well.  Nothing wrong with that, and its a simple statement.

Andy

So simple I wasn't able to figure out how to do it. Wink [;)] (Please see above where I said I was "very new" to VS.NET.) Any pointers?

ajj3085 replied on Monday, June 19, 2006

Just before your DoWork event handler finishes (and is successful) store the Thread.CurrrentPrincipal in an instance variable.

Then in your backgroundworker's RunWorkerCompleted event, set Thread.CurrentPrincpal equal to the instance variable you used to store the principal at the end of your DoWork event handler.

Make sense?

Andy

Norma_B replied on Monday, June 19, 2006

Got it. (For some reason, I was looking on the BackgroundWorker component for the Thread info, which is pretty daft in retrospect.) It's working now, but I had to move the assignment of the stored Principal to code called after RunWorkerCompleted in order to get it to work. Don't know if that should worry me or not.

ajj3085 replied on Monday, June 19, 2006

Well, as long as the thread you care about has the proper principal, i wouldn't worry about it.

Copyright (c) Marimer LLC