G'day all,
I'm implementing CSLA with VB and it would seem some of the codegeneration templates are a little out of date or broken from the codeplex web site, so I'm looking for a simple set of examples for each of the different framework implementations. I'm currently using v2.2 of the framework
Lets take and example of "Inherits CommandBase"
In Rocks book "Expert VB2005 Business Objects" and the ProjectTracker20vb solution there is
<Serializable()> _
Private Class ExistsCommandInherits CommandBase
Private mId As Guid
Private mExists As Boolean
Public ReadOnly Property Exists() As Boolean
Get
Return mExists
End Get
End Property
Public Sub New(ByVal id As Guid)
mId = id
End Sub
Protected Overrides Sub DataPortal_Execute()
Using cn As New SqlConnection(Database.PTrackerConnection)
cn.Open()
Using cm As SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.Text
cm.CommandText = "SELECT Id FROM Projects WHERE Id=@id"
cm.Parameters.AddWithValue("@id", mId)
Dim count As Integer = CInt(cm.ExecuteScalar)
mExists = (count > 0)
End Using
End Using
End Sub
End Class
However the codegeneration for VB command.cst (codesmith) failes to generate and includes BeforeServer and AfterServer methods and what looks like a completely different approach to building commandBase inherited objects.
Is there a place where you can get empty code examples for all the different components of the CSLA we can build/modify codegeneration templates or snippits to implement that structure? I realise this is a moving target, but it might make it easier to get the codegeneration templates uptodate in the VB area.
Jamie,
There is no such place (that I am aware of.)
I have been using CSLA for 4 years now and have built my own templates to match my architecture. Whenever I have a question about something I re-read the book and look at the samples and see if my ideas are basically in line with that.
For example my architecure reduces all the ADO.Net code above to 1 line. But the rest of the structure of a Command Object is pretty much the same.
If you build a few BOs and work with them for a while then you can figure out the best way to make templates of them to match your architecture and coding style. I tried to do everything all at once and while it eventually worked, it was a bit overwhelming. If you can focus on 1 BO type and then develop the template for that one fully, you will be better off. The template development time pays off big time down the road when you need to build new BOs. I can code-gen many BOs in just a few seconds now.
Joe
Copyright (c) Marimer LLC