After reading this article : http://www.willstrohl.com/Blog/EntryId/440/Shared-or-Static-Methods-versus-Singleton-Methods
and reviewing where Shared versus Singleton methods have been used throughout DNN Controllers and DAL, I now find myself totally confused.
For example: the Survey Module uses Shared methods in its controller whereas the HTML module using Singleton methods in its implementation.
Surveylist = SurveyController.GetSurveys(ModuleId) versus grdVersions.DataSource = objHTML.GetAllHtmlText(ModuleId)
In looking at other core controllers methods, PortalController, FolderPermissionController, TabController.GetPortalTabs, FillUserCollection & FillUserInfo, RoleController, EventLogController and others, some are Shared and others are defined as Singleton, requiring you to declare a new instance of a class. Example:
Dim ctlCustomer As New CustomerController
Dim intCustomerId As Integer = ctlCustomer.GetCustomerIdByName('John Doe')
-- OR SOMETIMES SHORTCUT TO:
Dim intCustomerId As Integer = (New CustomerController).GetCustomerIdByName('John Doe')
How should we be creating and accessing custom module controller method, Shared or Singleton and what are the performance/memory ramifications for each? For example; if I am looping through a large array of items and can calling a query (via DAL) for each item, does that dictate that I use one over the other?
If I implement my controller to utilize the DNN "cached object" DAL methods, does that make a difference as to where Shared or an Instance methods should be used?
Any guidance as to when to use each of the different methods is much appreciated.