You can use MDriven Framework to turn an MDriven model into a .NET application foundation, then add business-specific C# code that works directly with the model's generated types.
MDriven Framework combines MDriven Designer models with generated .NET code, persistence mapping, and runtime services. It is for developers who need to implement application-specific behavior in C# while keeping the model as the source of truth for the domain structure.
What you can do with MDriven Framework
With MDriven Framework, you can:
- Model domain classes, attributes, associations, and rules in MDriven Designer.
- Generate the business-layer code that corresponds to the model.
- Access model classes and types from C# with strong typing. For example, if the model contains an
Orderclass, your C# code works withOrderrather than untyped records or manually maintained mapping code. - Add custom C# behavior in separate partial-class files, often called CodeDress, so that regeneration does not overwrite your handwritten code.
- Derive and evolve the database schema from changes to the model while preserving existing data through database evolution.
- Build standalone .NET clients or servers, or compile model behavior for use with MDriven Turnkey.
MDriven Framework is not limited to a particular user interface. The framework can be used with application types such as WPF and Windows Forms, while MDriven Turnkey provides a model-driven web application front end. See Documentation:MDriven Product Line for how MDriven Designer, Framework, Turnkey, and MDrivenServer fit together.
How the model-to-code workflow works
The model is the central definition of the application's domain. MDriven Framework derives code and persistence information from that model, while your project supplies the business behavior that is unique to your application.
- Define or update the domain model in MDriven Designer. For example, create
CustomerandOrderclasses and an association that represents a customer's orders. - Generate or synchronize the Framework code from the model.
- Add business-specific logic in C# partial classes outside the generated files. For example, add an operation that validates whether an order can be submitted.
- Build the project. The custom code can use the generated
CustomerandOrdertypes directly. - When the domain changes, update the model and synchronize again. MDriven Framework updates generated code and persistence mapping; the separate custom-code files remain available for your logic.
This separation is important: generated code represents the model, while your CodeDress represents behavior that the model does not fully express.
Strongly typed C# access
Strongly typed means that the C# compiler knows the model types and their members. You can write code against the classes defined by the model and get compile-time checking when the model changes.
For example, when Order is a model class with an association to Customer, custom code can express business logic in terms of those domain concepts:
partial class Order
{
public bool CanSubmit()
{
return Customer != null;
}
}
The example illustrates the intended style: the code refers to the generated model type Order and its model-defined relationship Customer. Keep manually written behavior in a separate partial-class file rather than editing generated code.
Put rules in the right place
Use the model and its declarative capabilities for rules that belong in the model. Use C# CodeDress when a rule needs .NET code, external libraries, or implementation detail that is not suitable for the model.
| Need | Use | Example |
|---|---|---|
| A domain structure or relationship | MDriven Designer model | Model Customer, Order, and the customer-to-orders association.
|
| A declarative business expression | OCL | Express a condition or derivation using model concepts. |
| Custom implementation behavior | C# partial class / CodeDress | Call a .NET library or implement an operation that uses generated model types. |
| A Turnkey application behavior that requires compiled code | MDriven Framework output used with MDriven Turnkey | Make compiled model behavior available to a Turnkey application. |
OCL (Object Constraint Language) is used for declarative expressions against the model. C# is appropriate when the behavior needs ordinary .NET implementation code. Both approaches can work with the same domain model.
Generated code and custom code
Do not place handwritten changes in generated files. MDriven Framework is designed to regenerate and merge model-derived changes as the model evolves. Put your additions in separate partial classes so they are not replaced during generation.
A practical file layout separates generated and handwritten code conceptually:
Order.generated.cs <- generated from the model
Order.cs <- your partial class and custom business logic
The exact filenames are project-specific. The key rule is that the handwritten partial class must be separate from the generated source.
Database and persistence support
MDriven Framework derives database schema information, domain classes, and mapping information from the model. When you change the model, database evolution updates the schema while preserving data.
The framework supports persistence through PersistenceMapper interfaces. Documented database options include SQL Server, Oracle, MySQL, Firebird, Mimer, NexusDB, SQLite, Blackfish, and Sybase. For applications using MDrivenServer, the PersistenceMapper API supports multi-user data access features such as transactions, optimistic locking, client synchronization, CRUD operations, and OCL queries executed as SQL. See Documentation:MDriven Server User/Web interface for the server interfaces.
Runtime capabilities
MDriven Framework includes optional domain-runtime capabilities, including:
- A domain-layer undo and redo stack.
- Versioning for selected classes.
- Declarative Action definitions.
Use these features when they fit the behavior of your domain. They are framework services available to your application; they do not replace the need to define the domain model and its business rules.
When to use MDriven Framework
Choose MDriven Framework when you need to build a .NET application around an MDriven model and write business-specific C# against that model.
Typical uses include:
- A standalone client or server that uses model-derived domain classes and persistence.
- An application that needs custom .NET libraries alongside model-driven code.
- A Turnkey solution that needs compiled CodeDress behavior in addition to declarative model behavior.
- A system where model changes must be reflected consistently in code and database structure.
If you are starting with a model created in MDriven Designer and want to bring it into a Framework project, follow Documentation:Moving your work from MDriven Designer to MDriven Framework. For the broader architecture and development flow, read Documentation:How does MDriven work.
Continue learning
Use the Framework documentation hub to choose a task-oriented guide, including setup, Visual Studio integration, code generation, persistence, and CodeDress debugging. API-level reference material is available from Documentation:Api documentation.
