Shared Parts
- 3 minutes to read
Important
Domain Component (DC) interfaces are abstractions above eXpress Persistent Objects (XPO) classes. Notwithstanding its benefits, this abstraction imposes certain technical limitations. DC is only suitable for certain usage scenarios. The Blazor User Interface is not supported for DC. DC is in maintenance mode and we do not recommend its use in new software projects. We recommend that you migrate DC interfaces to pure XPO classes.
When a Domain Component Interface is aggregated by several Domain Components registered as entities in the application, this interface must be registered via the ITypesInfo.RegisterSharedPart method. Registering Shared Parts leads to changes in the database schema (extra tables are created). That is why Shared Parts should be registered manually, rather then automatically.
[DomainComponent]
public interface IWorker { }
[DomainComponent]
public interface IManager : IWorker { }
[DomainComponent]
public interface IEvangelist : IWorker { }
public class MyModule : ModuleBase {
// ...
public override void Setup(XafApplication application) {
base.Setup(application);
XafTypesInfo.Instance.RegisterEntity("Manager", typeof(IManager));
XafTypesInfo.Instance.RegisterEntity("Evangelist", typeof(IEvangelist));
XafTypesInfo.Instance.RegisterSharedPart(typeof(IWorker));
}
}
Important Notes
Entities that aggregate the shared part must use base classes that meet the following criteria.
- The base class key property must be named Oid.
- The key property must be of type Guid.
- The key property must expose a public setter.
These restrictions are required to avoid possible collisions between the primary key values of shared parts used in different entities. If you are registering an entity that does not aggregate shared parts, these restrictions do not apply, and you can use any kind of base class (such as classes with integer key properties). Note that the DCBaseObject base class used by the ITypesInfo.RegisterEntity method overloads, without the baseClass parameter, conforms to all the listed requirements. Thus, unless you need to use a custom base class, you do not need to be concerned about the limitations described here when registering your entities.
- The IsExactTypeFunction does not operate with types that are shared parts. As a workaround, you can add an auxiliary property that returns the name of the shared part’s type, and use it in the criteria.
- Upcasting is not supported for Domain Components that are registered as shared parts.
- Custom Fields cannot be added to Shared Parts.
- Entities cannot be filtered by the contents of a nested collection of shared parts using Oid property.