Quantcast
Viewing all articles
Browse latest Browse all 764

Moving from 3.8 to 4.5 confused about best way to go with private backing fields

I just got a contract to upgrade a pretty unique CSLA 3.8 business layer to 4.5. Because of the way they do property backing I am confused as to how to move forward.  Oh and it is VB.NET :-(

Several things that stand out:

  1. Root editable object receives and wraps a DTO which represents all the data (full object graph of root and all children).  The DTO has the root and up to grandchildren within it.  So the root editable object hydrates its own properties with the DTO and then hands the parts of the DTO to get child business objects created.  This happens when the data portal is crossed.  So the actual.
  2. The DTO within the business objects has its own change tracking...and the Data Access Layer is already coded to deal with the DTOs.
  3. They manually handled isChild, isDirty, isValid, and PropertyHasChanged

So here is a quick example...i'll try to keep it brief and to the point

Public Class RootPerson (inherits BusinessBase)

  private mPersonDTO

  <nonserialized><notundoable> private mPhoneNumbers as PhoneNumberList

  Public Property LastName As String

    Get

       Return mPersonDTO.LastName

    End Get

        Set(ByVal value As String)
            If mPersonDTO.LastName <> value Then
                mPersonDTO.LastName = value
                PropertyHasChanged("LastName")
            End If
        End Set

  End Property

  Public Property PhoneNumbers As PhoneNumbersList

    Get

      Return mPhoneNumbers

    End Get

  End Property

  <after returning from the Data Portal a method HydrateChildLists() is called (not included here for brevity)

  Private Sub HydrateChildLists()

    mPhoneNumberList = PhoneNumberList.NewFromDTO(mPersonDTO.PhoneNumbers)

  End Sub

  Public Overrides ReadOnly Property IsValid() As Boolean

        Get
            Dim blnValid As Boolean

            blnValid = MyBase.IsValid _
                AndAlso mPhoneNumberList.IsValid

            Return blnValid
        End Get
    End Property

    Protected Overrides Sub PropertyHasChanged(ByVal propertyName As String)
        'overridden so we don't call mark dirty since the DTO takes care of that
        ValidationRules.CheckRules(propertyName)
        OnPropertyChanged(propertyName)
    End Sub

End Class   

___________________________________

I think you get the idea.  It was the old way of manually doing the business objects with manual tracking and does not use propertyinfo helpers. 

I guess given the thousands of lines of code that is already working...I am wondering if I should just stick with it or rip the guts out and redo using propertyinfo fields?

The only problem I see with sticking with the way it is...is there is no longer an overrides for PropertyHasChanged(propertyName As String).  I think that is the only thing I would need to deal with.

I could upgrade the bazillions on properties yes...but whats the payoff if the stuff is already written?  I am a practical guy.

but on that note...if I were to upgrade all the properties...would this be the best way?

    Public Shared LastNameProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(Function(c) c.LastName, RelationshipTypes.PrivateField)
    Public Property LastName() As String
        Get
            Return GetProperty(LastNameProperty, mPersonDTO.LastName)
        End Get
        Set(ByVal value As String)
            SetProperty(LastNameProperty, mPersonDTO.LastName, value)
        End Set
    End Property

Thanks guys & gals

 


Viewing all articles
Browse latest Browse all 764

Trending Articles