Vibrant discussion about CSLA .NET and using the framework to build great business applications.
I want to implement the NameValueList class for an Encapsulated Invoke Dataread model.
Here is the code:
Imports Csla<Serializable()> _Public Class CodeTypeList Inherits NameValueListBase(Of Integer, String)
Private Shared list As CodeTypeList
Public Shared Sub InvalidateCache() list = Nothing End Sub#If Not SILVERLIGHT Then Public Shared Function GetNameValueList() As CodeTypeList If list Is Nothing Then list = DataPortal.Fetch(Of CodeTypeList)() End If Return list End Function#End If Public Shared Sub GetNameValueList(id As Integer, callback As EventHandler(Of DataPortalResult(Of CodeTypeList))) If list Is Nothing Then DataPortal.BeginFetch(Of CodeTypeList)(id, Sub(o, e) list = e.[Object] callback(o, e) End Sub) Else callback(Nothing, New DataPortalResult(Of CodeTypeList)(list, Nothing, Nothing)) End If End Sub
Private Overloads Sub DataPortal_Fetch()
IsReadOnly = False
Dim rlce = RaiseListChangedEvents
RaiseListChangedEvents = False
Using dalManager = DataAccess.DalFactory.GetManager()
Dim dal = dalManager.GetProvider(Of DataAccess.ICodeTypeListDal)()
Using data = dal.Fetch() While data.Read() Me.Add(New NameValuePair(data.GetString(data.GetOrdinal("CODEVALUE")), data.GetString(data.GetOrdinal("CODEVALUE2")))) End While End Using
End Using RaiseListChangedEvents = rlce IsReadOnly = True
End Sub
End Class
I have created the necessary Dal and IDals for this. Is this the correct method? In CSLA 2 this was a single-class act, but to maintain portability I guess I need to go down the Dal route. Correct?
Thanks,
Graham