I have created extended Identity objects for several projects. As long as the new properties are providing information about the current user, it is a natural fit.
If you want to store other data that isn't about the user, then I'd suggest Csla.ApplicationContext.ClientContext.
The only issue you'll encounter when creating a custom Identity object, is that you need to cast it to your specific type to get at your custom properties. This can become a PITA over time. So what I typically do is create a Security static class/Module that delegates all calls down:
Public Module Security
Public Function IsInRole(role As String) As Boolean
Return Csla.ApplicationContext.User.IsInRole(role)
End Function
Public ReadOnly Property Name() As String
Get
Return Csla.ApplicationContext.User.Identity.Name
End Get
End Property
Public ReadOnly Property Department() As String
Get
Return CType(Csla.ApplicationContext.User.Identity, CustomIdentity).Department
End Get
End Property
' ...
End Module
This way your app code can just always use the Security class:
x = Security.Name
y = Security.Department
Sometimes I call it "Security", other times "CurrentUser" - but you get the idea.
I see you bought the 2.1 Handbook, and that explains
ApplicationContext and the various context options you can use.
ClientContext flows from client to server, but not back. So it
is often a good option for ambient, global and generally unchanging values.
Keep in mind, however, that ClientContext and GlobalContext DO
flow across the network if you have a remote app server, and so you MUST be
careful how much stuff you put in them or performance could really suffer!
Rocky
From: dagware
[mailto:cslanet@lhotka.net]
Sent: Saturday, August 04, 2007 3:35 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] OK to use Csla.ApplicationContext.User for
other info?
Thanks for the reply!
So does Csla.ApplicationContext.ClientContext persist in basically the same
manner as the User object does? In other words, Web apps get it restored during
every trip back to the server, assuming the user is logged in? If so, it makes
more sense to me to use this for the selections the user makes, since they
aren't really part of the user's identity.
As for the helper static class -- I'm right there with you. I already wrote one
<g>.
Dan
RockfordLhotka:Keep in mind, however, that ClientContext and GlobalContext DO flow across the network if you have a remote app server, and so you MUST be careful how much stuff you put in them or performance could really suffer!
Copyright (c) Marimer LLC