Business Rules Persisting Between Instances Derived from BusinessBase

Business Rules Persisting Between Instances Derived from BusinessBase

Old forum URL: forums.lhotka.net/forums/t/9718.aspx


RumbleCow posted on Friday, November 05, 2010

I have noticed that business rules are persisted between instances derived from BusinessBase.  What am I doing wrong.  I've tried explicitly null the instance when done.  Please help.

 

 

                InboundPOAppointment appointment = InboundPOAppointment.NewInboundPOAppointment();

                appointment.Type = InboundPOAppointment.eInboundPOAppointmentType.Reserved;

                appointment.Date = dtpAppointmentCalendar.Value;

                appointment.StartTime = startTime;

                appointment.StopTime = stopTime;

                appointment.DockName = _CurrentDock;

                appointment.RegionNumber = _Region;

                appointment.FacilityNumber = _Facility;

 

                appointment.ApplyEdit();

 

                // saves appointment

                InboundPOAppointment savedAppointment = appointment.Save();

 

            appointment = null;

            savedAppointment = null;

 

// during the save two additional rules are added

When I turn around and create another instance of InboundPOAppointment the two additional rules are there.

 

 

 

 

 

RockfordLhotka replied on Friday, November 05, 2010

I don't understand what you mean by "rules are added". You mean you associate rules with the type in the save process?

The only place you should associate rules with a type is in AddBusinessRules. Rules are associated with a type exactly one time per AppDomain lifetime, and they are cached for the lifetime of that AppDomain. There is no provision for dynamically adding/removing rule associations. If you need different rule sets, use the CSLA 4 rule set feature.

RumbleCow replied on Friday, November 05, 2010

In a header/detail relationship I was saving the header in order generate an Id so that details records would have access.  I was adding rules (BusinessRules.AddRule(new Csla.Rules.CommonRules...) in the DataPortal_Fetch and DataPortal_Update to add a required Id rule so that it would be avaialbe to the children which is the culprit so the next new instance would already have the added rules..  I remember now reading awhile back that this is handled in the Editable Parent so move the Requied Id rule back and delay the save.

 

As always, thanks for the quick response.  Enjoying using 4.0.1-100828.  Recently came from 2.1.1-070223/

 

Keep up the GREAT work!!!

 

Keith

Copyright (c) Marimer LLC