6

I'd like to learn CSLA.NET quickly. What advice do you have?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
KG Sosa
  • 21,565
  • 6
  • 26
  • 27

7 Answers7

23

I would suggest downloading the CSLA source code and the samples (especially the ProjectTracker sample) and take a look at the code. The best way for me to learn something fast is to build something.

To start writing objects, start by creating the dataportal infrastructure.

e.g. Here is a base CSLA object:

[Serializable()]
public class Widget : Csla.BusinessBase<Widget>
{
    private Widget()
    {
    }
}

The next step to creating the dataportal is to determine what a fetch may look like on your object. E.g., are you going to want to get an object based on their id, their name, their category, or some other property. Here is an example of the same object with the fetch factory method implemented:

[Serializable()]
public class Widget : Csla.BusinessBase<Widget>
{
    private Widget()
    {
    }

    public static Widget Fetch(int id)
    {
        return Csla.DataPortal.Fetch<Widget>(new Csla.SingleCriteria<Widget, int>(id));
    }
}

The next step is to create the dataportal method that the CSLA data portal will create.

[Serializable()]
public class Widget : Csla.BusinessBase<Widget>
{
    private Widget()
    {
    }

    public static Widget Fetch(int id)
    {
        return Csla.DataPortal.Fetch<Widget>(new Csla.SingleCriteria<Widget, int>(id));
    }

    private void DataPortal_Fetch(Csla.SingleCriteria<Widget, int> criteria)
    {
        // Connect to database (or use ORM) and populate the object here based on the criteria.Value which is the id value
    }
}

After this is completed, the next step would be to define your business object with properties, etc. This is where you will want to look at the samples provided and see how parent/child relationships are defined, etc.

Hope this helps you get started.

You can download the code and the samples at http://lhotka.net/cslanet/Download.aspx

Jamie Wright
  • 1,160
  • 10
  • 23
9

The answer to this question all depends on your definition of the words "learn" and "fast". In my experience, no one ever learns anything fast.

That being said I would suggest you visit Rockford Lhotka's site and check out the forums and books that are there.

http://www.lhotka.net/cslanet/
http://forums.lhotka.net/

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
8

Get the book. Read the book. Start using the framework :o/

I've been working with CSLA.Net for 4 years and I'm still learning new tricks and features every week :o)

Andrew
  • 12,991
  • 15
  • 55
  • 85
  • 3
    I have to agree. If you don't read the book, you will most likely wind up repeatedly posting questions about how to use it or never quite using it to its full potential. The first 200 pages of the book give a good overview of its use. From there I was able to skip around as needed. There is a large chunk of the book that goes over the design and implementation of the framework under the covers such as how DataPortal works. You can get by without reading those parts. – Richard Collette Sep 29 '11 at 21:23
2

I would highly recommend checking out our CSLA 3.8 templates. They come in both a VB.NET and a C# flavor. We are currently working on a major release that adds SQL Stored Procedure, Object Factory and Many-to-Many support. It is a great starting point because we have real world examples like the Microsoft PetShop Sample application that is completely generated (both the business layers and data access layers ) with unit tests to show you exactly how CSLA works. If you have any questions or run into issues we are here to help you understand and grow as a CSLA developer.

Another great compliment to learning CSLA is purchasing the following book: Expert C# 2008 Business Objects.

Thanks -Blake Niemyjski (Author of the CodeSmith CSLA Templates)

Blake Niemyjski
  • 3,432
  • 3
  • 25
  • 41
1

I would suggest you read this book from Rockford to get you started understanding the rationale behind the framework and how everything fits together

Rad
  • 8,336
  • 4
  • 46
  • 45
0

Magenic (Rocky's company) offers several CSLA master Classes throughout the year which are excellent and will give you an immersion experience.

Bob Par
  • 161
  • 2
  • 5
0

My best suggestion is don't. There are many data access architectures that are more robust, more maintainable, better performing, and more widely accepted in the industry. NHibernate, Linq-to-Sql, and Microsoft Entity Framework are three. Go with the industry. Don't be the lone ranger.

Anthony Gatlin
  • 4,407
  • 5
  • 37
  • 53
  • 4
    A little dated, but take a look at this: http://www.lhotka.net/weblog/ADONETEntityFrameworkLINQAndCSLANET.aspx "ADO.NET EF ... works with entity objects - objects designed primarily as data containers." "CSLA .NET is all about creating business objects - objects designed primarily around the responsibilities and behaviors defined by a business use case. It is all about making it easy to build use case-derived objects that have business logic, validaiton rules and authorization rules." – Keith Sirmons Oct 12 '09 at 16:59
  • Csla isn't an ORM, this answer is exteremly misleading. – Andy Mar 30 '11 at 01:50
  • 4
    Duh. I know CSLA is not an ORM. However, many people use bloated unmanageable frameworks like CSLA because they are trying to reduce the amount of coding and maintenance they actually have to do. It's a fools errand. My point was simply that if a person's objective is to use a framework that will allow quick implementation of an application, entity framework (now that linq-to-sql is dead) or nhibernate would be better solutions. I've worked with CSLA and while it can be implemented rather quickly, it is a freaking maintenance nightmare. – Anthony Gatlin Oct 17 '11 at 23:03
  • 6
    I know this was a long time ago, but I would also like to add that this answer is very misleading. CSLA is not about the data but the business, its rules and its validations. I have worked with CSLA and would say that initially I found it a bit bloated; however, when I got to know its depths, I found it to be an extremely good framework that provided structure (for developers) and strength to applications built with it. IMO apps that are a maintenance nightmare are usually so because of bad design/planning or the pressures of time placed on developers by management. – iWeasel Dec 17 '11 at 12:54