I could be wrong, but it seems that the general practice for collection type properties is to initialize the property's field with its collection.
I have inherited from CslaIdentity and found it beneficial to initialize the property as shown below. Is this something that should be done within CslaIdentity itself?
''' <summary> ''' A list of role names (functions) associated with the user. ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks>.NET Roles are mapped to AppSec functions.</remarks> Protected Overloads Property Roles() As Csla.Core.MobileList(Of String) Get 'Create a new roles list if it does not exist so that we don't have to constantly do this check. If MyBase.Roles Is Nothing Then MyBase.Roles = New Csla.Core.MobileList(Of String) End If Return MyBase.Roles End Get Set(ByVal value As Csla.Core.MobileList(Of String)) MyBase.Roles = value End Set End Property
The assumption is that the list of roles is initialized when the object is being loaded with data in the data portal. Because the list of roles is often loaded from the result of a LINQ query, it is then more efficient to create the Roles list directly off the query result - or if not more efficient, it is simpler code.
In short, CslaIdentity doesn't create the list, because I don't know how you will be creating or initializing the list and I don't want to impose one model on you when another model might work better.
Copyright (c) Marimer LLC