CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Call for design change in codegen templates

Last post 09-10-2008, 3:22 AM by IanK. 1 replies.
Sort Posts: Previous Next
  •  09-06-2008, 1:17 PM 25995

    Call for design change in codegen templates

    Although the codegen templates that are out there are all pretty good there is something which I think is a great miss at the moment.

    In my projects I always work with a pattern where the Business Objects make use of a data repository class to retrieve raw record data from the database and perform other CRUD related operations. The contract for the repository class is pretty simple. Each method accepts a Data Transfer Object with the data and returns either a collection of DTO's or a single DTO as result or in the case of a delete operation nothing.

    The repository classes are seperated by using an interface and letting a separate factory class construct the actual instance for me. This enables the use of Inversion Of Control mechanics like Spring.NET or recently Unity.

    A typical DataPortal_Select method may look like this:

    private void DataPortal_Select(SingleObjectCriteria x) {
      IMyDataRepository repository = RepositoryFactory.CreateMyDataRepository();
      MyData rawData = repository.SelectById(x.Id);

      LoadObjectData(rawData); //Load the raw object data from the DTO
    }

    What I would like to see in more codegen templates is something similar to this. The factory in this case may be a simple matter of just returning a new instance of the right repository by using the new operator. This will provide developers with an even better way to extend the possibilities of the generated code and more importantly you can provide mockups for the repository classes and test the business objects seperately.

    I would love to hear your thoughts on this and I hope that more people see the advantages of this pattern.
  •  09-10-2008, 3:22 AM 26074 in reply to 25995

    Re: Call for design change in codegen templates

    You might want to check out Miguel Castro from Steelblue (See link on Website) CSLAex library. He uses a single DataAccess layer similar to what you are discussing and his codegenerator default templates target towards this. 

    I adopted his code and for example have a fetch something like this:

    Private Overloads Sub DataPortal_Fetch(ByVal criteria As Criteria)

    Using reader As SafeDataReader = _

    New DAC.CentralDataAccess(True).ReaderFromProcedureById(Of Integer)("ProcName", criteria.ID)

    If reader.Read() Then

    Try

    PopData(reader)

    Catch ex As Exception

    Throw

    End Try

    End If

    End Using

    End Sub

     

View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems