Skip to main content
A newer version of this page is available. .

ITypesInfo.RegisterDomainLogic(Type, Type) Method

Registers a specific class as the Domain Logic of a specific Domain Component interface.

Namespace: DevExpress.ExpressApp.DC

Assembly: DevExpress.ExpressApp.v19.1.dll

Declaration

void RegisterDomainLogic(
    Type interfaceType,
    Type logicType
)

Parameters

Name Type Description
interfaceType Type

A Type object, representing a type of the interface to which the Domain Logic should be assigned.

logicType Type

A Type object, representing a type of a class providing the Domain Logic to be registered.

Remarks

Typically, when implementing Domain Components, you decorate the class specifying the Domain Logic with the DomainLogicAttribute, and pass the Domain Component interface type as the attribute’s DomainLogicAttribute.InterfaceType parameter. Another approach of linking the Domain Logic class with the Domain Logic interface is using the RegisterDomainLogic method. Consider the following example:

using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
// ...
[DomainComponent, DefaultClassOptions]
public interface IPerson {
    string FirstName { get; set;}
    string LastName { get; set;}
    string FullName { get; }
}
public class PersonLogic {
    public static string Get_FullName(IPerson person) {
        return string.Format("{0} {1}", person.FirstName, person.LastName);
    }
}
public sealed partial class MySolutionModule : ModuleBase {
    // ...
    public override void Setup(XafApplication application) {
        base.Setup(application);
        XafTypesInfo.Instance.RegisterEntity("Person", typeof(IPerson), typeof(BaseObject));
        XafTypesInfo.Instance.RegisterDomainLogic(typeof(IPerson), typeof(PersonLogic));
    }
    //...
}

This approach can be useful when you do not want (or cannot) modify the Domain Logic class sources, to link the Domain Logic to another Domain Component, or override the Domain Logic with your custom logic.

If there are several Domain Logics registered for the same Domain Component, the last registered logic supplements the others. Methods implemented by existing Domain Logics remain active.

public interface ISampleObject {
    string Property1 { get; }
    string Property2 { get; }
    string Property3 { get; }
}
public class SampleObjectLogic1 {
    public static string Get_Property1(ISampleObject obj) { return "Text1"; }
}
public class SampleObjectLogic2 {
    public static string Get_Property2(ISampleObject obj) { return "Text2"; }
}
public class SampleObjectLogic3 {
    public static string Get_Property3(ISampleObject obj) { return "Text3"; }
}
public sealed partial class MySolutionModule : ModuleBase {
    // ...
    public override void Setup(XafApplication application) {
        base.Setup(application);
        XafTypesInfo.Instance.RegisterEntity("SampleObject", typeof(ISampleObject));
        XafTypesInfo.Instance.RegisterDomainLogic(
            typeof(ISampleObject), typeof(SampleObjectLogic1));
        XafTypesInfo.Instance.RegisterDomainLogic(
            typeof(ISampleObject), typeof(SampleObjectLogic2));
        XafTypesInfo.Instance.RegisterDomainLogic(
            typeof(ISampleObject), typeof(SampleObjectLogic3));
    }
}

RegisterDomainLogic

Important

If you register several Domain Logic classes for a single Domain Component, they should not overlap (implement the same methods). Otherwise, the following exception will occur:

There are '2' logics found for 'Get_Property1()' for 'MySolution.Module.BusinessObjects.ISampleObject':

Solution2.Module.BusinessObjects.SampleObjectLogic1.Get_Property1 with instance parameter

Solution2.Module.BusinessObjects.SampleObjectLogic2.Get_Property1 with instance parameter

You can use the ITypesInfo.UnregisterDomainLogic method to remove an unwanted Domain Logic.

Tip

You can unregister the Domain Logic with the ITypesInfo.UnregisterDomainLogic method.

See Also