My question is this...
Must I have a private constructor in a ReadOnlyBase object?
I have a SecurityPolicy object that has a couple of validation methods (to verify proper password format, expired passwords, account lockouts, etc.). Each of these methods returns a SecurityPolicyStatus object that provides the result of the validation method, as well as a list of any broken policies. This object is intended for internal consumption and should not be used by the UI. The SecurityPolicyStatus object is instantiated and populated directly by each of the respective SecurityPolicy object methods, based on data existing inside the SecurityPolicy object. Consequently, there is no need for any DataPortal methods in the SecurityPolicyStatus object to retrieve data from the database. Below is the code of my object (please note that Base.LVReadOnlyBase is a subclass of Csla.ReadOnlyBase). It does not currently have a private constructor.
[Serializable()]
internal class SecurityPolicyStatus : Base.LVReadOnlyBase<SecurityPolicyStatus>
{
# region Properties
private Guid _id = Guid.NewGuid();
private bool _isValid;
private List<string> _brokenPolicies = new List<string>();
/// <summary>
/// Determines whether or not the validation method
/// passed the required security policies.
/// </summary>
internal bool IsValid
{
get { return _isValid; }
set
{
_isValid = value;
}
}
/// <summary>
/// Gets a list of broken security policies.
/// </summary>
internal List<string> BrokenPolicies
{
get { return _brokenPolicies; }
}
# endregion
#region Business Methods
/// <summary>
/// Adds a broken security policy to the <see cref="BrokenPolicies"/> list.
/// </summary>
/// <param name="item">
/// A string describing the security policy that was broken.
/// </param>
internal void AddBrokenPolicy(string item)
{
_brokenPolicies.Add(item);
}
/// <summary>
/// Returns a unique identifying value for the object.
/// </summary>
protected override object GetIdValue()
{
return _id;
}
#endregion
#region Constructors
/// <summary>
/// Class constructor
/// </summary>
internal SecurityPolicyStatus(){ }
#endregion
}
The internal constructor is used by the SecurityPolicy object to instantiate the SecurityPolicyStatus object.
My confusion comes from the ResourceInfo object in the CSLA.Net book (page 448). It provides both private and internal constructors. The book states that the private constructor prevents the UI from instantiating the object. But, doesn't the internal constructor also prevent the UI from instantiating the object? My assumption is that the business objects are contained within their own assembly, separate from the UI (like the ProjectTracker.Library is).
I realize this is a very basic question and apologize in advance for any offense. I just want to solidify my understanding before I get too deep and discover that I missed something fundamental that will require recoding.
Thanks for your help.
One other thing to consider:
Every class in your library does NOT need to derive from CSLA. In this case you are probably better off skipping the inheritance entirely. Now you "stand alone" class is clearly something used internally by the parent class. You can create instances of it and store them, etc.
Joe
Copyright (c) Marimer LLC