MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

static property in Csla object #648

Open Chicagoan2016 opened 5 years ago

Chicagoan2016 commented 5 years ago

Hi All, We can declare different property types in Csla like Read/Write Properties, Child reference properties etc. I was wondering if there is a way to declare a Csla style static property in an object?

kind regards

Version and Platform CSLA version: 4.7.100 OS: Windows, Linux, iOS, Android, etc. Platform: WinForms, WPF, ASP.NET Core, MVC, Xamarin, etc.

rockfordlhotka commented 5 years ago

No, because a static value can't be safely serialized between client and server. That value is shared by everything in the entire AppDomain, so changes made to it need to be intentional.

If you are trying to have a global value that should be available on client and server, that value should be maintained in ApplicationContext.ClientContext or GlobalContext.

Chicagoan2016 commented 5 years ago

Thank you @rockfordlhotka , I am going to reread about ClientContext and Globalcontext : )

kind regards

Chicagoan2016 commented 5 years ago

@rockfordlhotka , we have used 'const strings' in static classes and these const strings store hard coded values, we did that to avoid remembering those hard coded values. Should we stop doing this while using Csla? Thanks and Regards

rockfordlhotka commented 5 years ago

As I'm sure you know, global values of any sort are considered an anti-pattern in general terms.

I'm just describing why CSLA doesn't have any construct around them. You can surely have them in your classes, but CSLA will ignore them, because they can't be safely serialized or managed by CSLA.

Chicagoan2016 commented 5 years ago

can't thank you enough @rockfordlhotka .

Should we go ahead and change static classes and their properties ( to store hard coded strings) to something based on Csla BusinessBase? We have used those classes to store default values for business properties in our business objects. I hope we didn't get ourselves in a mess : )