Design: Using a CheckState enum

Design: Using a CheckState enum

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


esteban404 posted on Wednesday, July 19, 2006

I have a few bool fields which require input from certain roles. I changed them to use the checkstate enum from the System.Windows.Forms namespace to allow me to initialize them to indeterminate for databinding, authorization and rule checking. It seems inappropriate (bloated) to add a reference of that type to a CSLA BO class.

So do I recreate it or just reference it (thus guaranteeing compatibility with form objects) and not worry?

_E

ajj3085 replied on Wednesday, July 19, 2006

I'd reference it.  It doesn't make your program any bigger linking to System.windows.Forms and under .Net, its always there.  Indeed, Csla itself links to both Forms and Web.

esteban404 replied on Wednesday, July 19, 2006

Thanks, ajj3085 (Andy?). I tried to open the source to look, but I only moved the assemblies to this machine. D'oh! It didn't seem to be a problem, so I thought I'd reenforce my claim to the crown as King of Stupid Questions. My boss loves to needle me on best practice questions.

Just downloaded the 1.53 zip again. :-]

_E

ajj3085 replied on Wednesday, July 19, 2006

Yes, I'm Andy.  I don't think this is a stupid question at all; I once wrote some code that needed to be used in Web or Windows, and of course the only way to check is to see if HttpContext.Current is non-null.  I felt odd about referencing the Web assembly at first, since that's the only reason I needed it.  I was comforted by the fact that Rocky does the same thing in Csla.  I suppose there's no other way, if for some reason you depend on being in an HttpContext.

malloc1024 replied on Wednesday, July 19, 2006

You want to try to avoid using the System.Windows.Forms namespace in your business layer.  It typically means that your UI logic is creeping into you business layer.  Your business layer should be completely independent of any UI. 

pelinville replied on Wednesday, July 19, 2006

Is there a reason you couldn't just create a Enum in the CSLA namespace that has the values you need?
 
You could even make a smartBool class to make handling this stuff even easier.

esteban404 replied on Thursday, July 20, 2006

pelinville:
Is there a reason you couldn't just create a Enum in the CSLA namespace that has the values you need?

Basically, it already exists (reinventing the wheel argument), and as noted, the namespace is insignificant to size the assemblies. I did create the enum in my library, but I needed to ensure it would match what is expected for databinding on forms, so I'd using the same namespace meets the requirement. When researching the definition, I found a mix of order for it, so getting just the right one was problematic without using it.

Now if this were going web, I'd rethink it more, but it's not.

_E

ajj3085 replied on Thursday, July 20, 2006

pelinville:
You could even make a smartBool class to make handling this stuff even easier.


The more I think about this, the more I think this solution makes more sense, and the less I like referencing the Forms assembly.

Copyright (c) Marimer LLC