Using Custom Data Access Classes
If you are using custom data access classes with your business objects (for example, your Inventory business object uses an InventoryDataAccess class), how can you tell your remote web service to instantiate this custom data access class? This involves three steps:
- In your business object's CreateDataAccessObject() method, pass the name of your custom data access class as a string to the constructor of the web service data access class.
For example, in C#:
protected override mmDataAccessBase CreateDataAccessObject(string dataAccessClassName) { if (mmAppBase.DefaultDataAccessMode == mmDataAccessMode.Local) { return new InventoryDataAccess(); } else { return new mmDataAccessWebServiceSql("InventoryDataAccess"); } }And in VB .NET:
Protected Overrides Function CreateDataAccessObject(dataAccessClassName As String) As mmDataAccessBase If mmAppBase.DefaultDataAccessMode = mmDataAccessMode.Local Then Return New InventoryDataAccess() Else Return New mmDataAccessWebServiceSql("InventoryDataAccess") End If End FunctionAt run time, this passes the name of the data access object to be instantiated to your Web Service.
- In your Web Service, you need to change your Factory.cs or Factory.vb code to check for the token you are passing and instantiate the corresponding data access class.
For example, in C#:
public class Factory : OakLeaf.MM.Main.Patterns.mmFactory { public override mmDataAccessBase CreateDataAccessObject(string dataAccessClass) { switch (dataAccessClass) { case "InventoryDataAccess": return new InventoryDataAccess(); case "OrdersDataAccess": return new OrdersDataAccess(); case "OrderDetailDataAccess": return new OrderDetailDataAccess(); default: break; } return base.CreateDataAccessObject(dataAccessClass); } }And in VB .NET:
Public Class Factory Inherits OakLeaf.MM.Main.Patterns.mmFactory Public Overrides Function CreateDataAccessObject(dataAccessClass As String) As mmDataAccessBase Select Case dataAccessClass Case "InventoryDataAccess" Return New InventoryDataAccess() Case "OrdersDataAccess" Return New OrdersDataAccess() Case "OrderDetailDataAccess" Return New OrderDetailDataAccess() Case Else End Select Return MyBase.CreateDataAccessObject(dataAccessClass) End Function End Class
- Finally, you need to add an assembly to your web service that contains the data access classes. You can choose to either reference your entire business object assembly, or you can place your data access classes into a different assembly and reference that assembly instead.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 09/23/10
Comment or report problem with topic
