CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Upgrading from 3.8.1 to 4.2.2

rated by 0 users
Not Answered This post has 0 verified answers | 12 Replies | 1 Follower

Not Ranked
14 Posts
PJ posted on Thu, Jun 28 2012 9:04 AM

Hi all,

I have a project which is using CSLA 3.8.1 with .NET F/W 3.5 and now that has to be converted to 4.2.2 with .NET F/W 4.0. Now that i am facing some issues is changes in method names and properties. For instance, "ValidationRules" class has been changed to "BusinessRules". So similarly "Csla.Rules.CommonRules.IntegerMinValue" has been changed to what? is there any place where I can see comparision? Please respond as this issue has bcome showstopper for me. Your early response would be appriciated Huh?

Thanks in advance.

All Replies

Top 10 Contributor
1,815 Posts

Hi,

The best resource on how to use CSLA 4 is Rockys ebook series: http://download.lhotka.net/Default.aspx?t=UsingCsla4

Available for purchase here. http://store.lhotka.net/Store/tabid/1560/ProductID/22/List/1/Default.aspx

And of course also the change log for each release: http://www.lhotka.net/cslanet/ 

The 3.x rule engine is gone and there is an entire new rule engine where all rules are classes in 4.x.

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
14 Posts
PJ replied on Fri, Jun 29 2012 3:39 AM

Thanks for quick response Mr.JonnyBee

I have a time constraint, I dont have enough time to read complete book. And change log is not so clear. Is there any other link where in I can get diff b/w various version, as I said I have very less time Sad

Top 10 Contributor
1,815 Posts

Hi,

Basic summery and few links in this release post:  http://forums.lhotka.net/forums/p/9260/43936.aspx 

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
14 Posts
PJ replied on Thu, Jul 19 2012 6:03 AM

Hi,

sorry for posting the comments on diffeent threads. now its that  Csla.Validation had public void AddRule(RuleHandler handler, IPropertyInfo propertyInfo); in 3.V now AddRule has only 5 overloaded 1. methods AddRule(System.Type objectType, Csla.Rules.IAuthorizationRule rule, string ruleSet) 2. AddRule(System.Type objectType, Csla.Rules.IAuthorizationRule rule) 3. AddRule(Csla.Rules.IAuthorizationRule rule) 4. AddRule(Csla.Rules.IBusinessRule rule, string ruleSet) 5. AddRule(Csla.Rules.IBusinessRule rule)

now i am adding a rule BusinessRules.AddRule(CustomRules.ValidatingExtendedBindingListIsValid<IDeviceInfo>, _deviceListProperty); where ValidatingExtendedBindingListIsValid is a class and IDeviceInfo is an interface which implements CslaExtensions.IReadOnlyBase, IDeviceKey, IEquatable<IDeviceInfo>

public class ValidatingExtendedBindingListIsValid<T> : BusinessRule where T : class

        {

               protected override void Execute(RuleContext context)

            {

                var value = Utilities.CallByName(context.Target, context.OriginPropertyName, CallType.Get);

                //var rv = true;


                var validatingCollection = value as ValidatingExtendedBindingList<T>;

                if (validatingCollection != null)

                {

                    var errorMessages = new List<string>(validatingCollection.ValidationErrors());

                    if (errorMessages.Count != 0)

                    {

                        var flattenedErrors = new StringBuilder();

                        foreach (var error in errorMessages)

                        {

                            flattenedErrors.AppendLine(error);

                        }

                        context.AddInformationResult(string.Format(CultureInfo.CurrentCulture,

                                                      Properties.Resources.CollectionHasValidationErrors,

                                                      context.GetType().GetProperty(context.OriginPropertyName),

                                                      flattenedErrors));

                    }

                }

            }

        }

now how do i add my rule?

Top 10 Contributor
1,815 Posts

create an instance of your rule and call BusinessRules.AddRule, ex:

BusinessRules.AddRule(new MyRule<type>(primaryProperty));

I do recommend that you buy the Using CSLA 4 : Creating Business Objects ebook. 

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
14 Posts
PJ replied on Thu, Jul 19 2012 6:27 AM

Yes, the class ValidatingExtendedBindingListIsValid was converted to implement BusinessRule , and as you see it does not have any constructor with no arguments. Also to add a point, i am bit new to OOPS conceptsCrying

Not Ranked
14 Posts
PJ replied on Fri, Jul 20 2012 4:21 AM

Hi,

as recommanded by you, i got the ebook, but in ebook no where Csla.Validations.DecoratedRuleArgs is mentioned. Really feeling diffuculties in upgradation, why so many breaking changes?

Top 10 Contributor
1,815 Posts

The ebook documents how to use CSLA 4.x - not 3.8x or migration to 4.x.

RuleArgs/DecoratedRuleArgs no longer exists in 4.x - you now use properties on your rule to pass/read values from the BO (possibly aided by the rule engine itself). 

The new rule engine provides the same progrmming model/unit testing experience no matter if he rule is sync or async and it is much easier to create generic - reusable rules. You should focus on understanding the new rule programming model - and how to wriite rules - rater the mapping fetures from the old rule engine. 

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
14 Posts
PJ replied on Fri, Jul 20 2012 4:54 AM

any recommanded books for conversion? if not any link(except change log) in the site which clearly specify changes from version to version?

Top 500 Contributor
15 Posts

Doing an upgrade without allowing yourself time to learn the changes is a stressful route to have chosen. There are rarely shortcuts to learning new things.

What is forcing the upgrade? If you are running on full .NET then using multiple .NET frameworks is fine; you should be able to compile your app against .NET 4.0 even if using CSLA 3.8x

Andrew H; Bucks, UK

Not Ranked
14 Posts
PJ replied on Wed, Sep 12 2012 9:01 AM

Hi,

Back with one more query, how to add the arguments to business rules?

Top 10 Contributor
1,815 Posts

If you think of parameters that can be defined in AddBusnessRules then add as properties on the rule class and add as parameter to constructor.

See f.ex MaxLength rule that gets the maxlength as a parameter.

  public class MaxLength : CommonBusinessRule

  {

    public int Max { get; private set; }

 

    public MaxLength(Csla.Core.IPropertyInfo primaryProperty, int max)

      : base(primaryProperty)

    {

      Max = max;

      this.RuleUri.AddQueryParameter("max", max.ToString());

      InputProperties = new List<Core.IPropertyInfo> { primaryProperty };

    }

         ........

Jonny Bekkum, Norway CslaContrib Coordinator

Page 1 of 1 (13 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems