🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Segmenting definition and logic
This page was created by Alexandra on 2017-11-09. Last edited by Wikiadmin on 2026-07-29.

You can split model definitions from their implemented logic by importing an .ecopkg for editing or by referencing it as a read-only package that is supplied by its own compiled assembly; this page is for MDriven Designer users who reuse model packages across solutions.

Choose how to reuse a package

An .ecopkg is a package of model definitions. Choose the reuse mode based on whether your solution owns and changes the package definition, or consumes a completed package together with its implementation.

Reuse mode Use it when What you can change Code and runtime result
Import the package into the model You want the package definition to become part of the current model and you need to edit it. The imported package contents are editable. Code generation includes the package. MDriven Designer creates code and empty stubs for code-implemented operations.
Reference the package through Edit referenced packages You want to reuse the complete model assembly, including code-implemented operations, code-derived attributes, relations, or other externally implemented logic. The referenced package classes are read-only in the current model. The referenced package is not generated with the current model. Its own compiled assembly or project must be available to the solution and at runtime.

Example: consume a membership package

A package such as EcoAspProvider.ecopkg can contain model definitions together with implementation of membership functions for ASP.NET as ECO objects. If your application uses that completed functionality without changing its definitions, add it as a referenced package. Your model can use its classes, while the membership package remains owned, built, and maintained separately.

Import a package that your model will own

Import a package when you want to modify its classes, attributes, associations, or operations as part of the current model.

  1. Import the .ecopkg into the model.
  2. Edit the imported definitions as needed.
  3. Generate code for the model.
  4. Implement any required code-implemented operation stubs in your solution.

For example, import a shared Sales package if the current solution must add an attribute to one of its classes or change an operation definition.

Reference a completed package

Reference a package when its definition and implementation belong to another model assembly. This keeps the external definition unchanged in the consuming model and prevents the current code-generation run from generating it again.

  1. In MDriven Designer, choose Edit referenced packages.
  2. Choose Add.
  3. Locate and select the .ecopkg that you want to reuse.
  4. Save the model.
  5. Add a normal .NET reference to the assembly or project that implements the referenced package.
  6. In the EcoSpace designer, click the choose package icon.
  7. Select every package that the EcoSpace must use at runtime.
  8. Generate code and build the solution.
  9. Generate the schema only after the solution builds successfully.

The build order matters. Schema generation derives the runtime model from code, so the generated code and the external package assemblies must be built before you generate the schema.

Work with read-only referenced classes

Classes from a referenced package are read-only because the external definition cannot be changed from the consuming model. MDriven Designer blocks attempts to change a property of a referenced package.

You can create associations between your local classes and referenced classes, with one important restriction:

  • You can make a local class point to a read-only referenced class.
  • You cannot add a new association end that makes the read-only referenced class point to something new.
  • You cannot embed an association end in a read-only end.

For example, if Order is a local class and MembershipUser comes from a referenced package, you can model an association from Order to MembershipUser. You cannot alter MembershipUser by adding a new outward association end to Order in the consuming model.

This rule preserves the external package definition while allowing your model to refer to it.

Make referenced packages available at runtime

Selecting packages in the EcoSpace designer makes them available at runtime. The designer creates a reference in the generated designer.cs code by adding a protected member whose type is the package type.

A generated reference has this form:

protected MDrivenPackage1.MDrivenPackage1Package IncludeEcoPackage_MDrivenPackage1_MDrivenPackage1Package;

If you cannot use the designer for this step, add an equivalent protected member to the EcoSpace class yourself. Use one member for each referenced package, give each member a unique name, and place the member anywhere in the EcoSpace class.

For example, if the EcoSpace uses two external packages, it needs two distinct protected members, each typed as its corresponding package type.

Troubleshooting

Problem Likely cause What to do
You cannot change a class or property from the package. The package is referenced, so its definitions are read-only. Change the external package in its owning model, or import the package instead if the current model must own and edit the definition.
The model compiles but a referenced package is unavailable at runtime. The package was not selected for the EcoSpace, or its implementation assembly/project is not referenced. Select the package with the EcoSpace designer's choose package icon and add the required .NET assembly or project reference.
Schema generation does not reflect the referenced package. Code generation and build were not completed before schema generation. Generate code, build the solution, then generate the schema.

See also