Custom Business Logic Implementation in MemberJunction

Beyond the foundational BaseEntity and the strongly typed generated subclasses, MemberJunction provides a flexible framework for implementing custom business logic. This is a critical aspect of the architecture, allowing developers to tailor the software to specific business needs and scenarios.

The Role of Custom Business Logic

📘

Custom business logic in MemberJunction refers to the unique rules and behaviors that define how an application should operate in specific contexts.

This encompasses validation routines, conditional logic, data flow processes, and other specialized functionalities that are not covered by the generic operations of the BaseEntity or its strongly typed subclasses.

Implementing Custom Business Logic

In MemberJunction, custom business logic is implemented through further subclassing of the strongly typed generated subclasses. This layered approach ensures that the core functionality provided by the BaseEntity and the schema-specific features of the strongly typed subclasses are preserved, while still allowing for bespoke customization.

  • Subclassing for Customization: Developers can create a second-level subclass deriving from the strongly typed, generated subclass. This custom written subclass is where your business logic is coded, enabling developers to extend or modify the base functionality to suit particular needs.
  • Examples of Custom Logic: A common use case for custom business logic is the implementation of validation routines. For instance, if certain fields in a form are interdependent, custom logic can be used to enforce these relationships, ensuring data integrity and consistency. Our sample application has examples of a custom sub-class that implements these concepts.

Maintaining Synchronization with Schema Changes

An important aspect of implementing custom business logic in MemberJunction is ensuring that these customizations remain synchronized with any changes in the database schema:

  • CodeGen Utility: The CodeGen tool in MemberJunction plays a crucial role here. While it automatically updates the strongly typed subclasses to reflect schema changes, it does so without altering your hand-written custom subclasses. This separation ensures that custom business logic remains intact and functional even when the underlying schema evolves.
  • Best Practices: Developers are strongly advised not to modify the automatically generated strongly typed subclasses directly. Instead, they should implement their customizations in the separate subclass deriving from the generated sub-classes. This practice avoids conflicts with the CodeGen process and maintains the integrity of the custom logic.