Domain Components+ Calculated properties + Application Model

Updated 2/9/2013
see end of post

Even though XAF does not support the idea of Domain Components + Calculated properties + Application Model out-of-the-box, XAF is still designed with the highest of standards. In this blog, I will demonstrate hot to achieve this concept of Domain Component + Calculated Properties + Application Model otherwise.

Domain Components

With XAF it is possible to design business objects from interfaces! Given those interface DC with smart algorithms create concrete persistent class at runtime. It is possible to explore the DC dynamic assembly by overriding the in solution’s WinApplication descendant as shown:

public partial class DynamicMemberAliases2WindowsFormsApplication : WinApplication {

    protected override string GetDcAssemblyFilePath() {

        return Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, DcAssemblyFileName);

    }

Exploring the DC assembly for the following DomainComponent1

[DomainComponent]

public interface DomainComponent1 {

    string Email { get; set; }

    string Twitter { get; set; }

}

public override void Setup(XafApplication application) {

    base.Setup(application);

    XafTypesInfo.Instance.RegisterEntity("Manager", typeof(DomainComponent1));

 

We find that XAF creates the next Manager class on the fly and that this class is a simple XPO persistent object and is specific to our DomainComponent1 (see the RegisterEntity method above).

 

 

image

This is really great! We already know how to create Dynamic member aliases though the Application Model and we can apply the same technique to the Manager class, which is very conveniently related only to the DomainComponent1. However, although the Dynamic member aliases can be successfully created in the Manager class, XAF would not know of their existence. In the next section we will discuss how to workaround this.

The TypesInfo system

  1. In XAF, everything is an object. To help resolve object types, we created a TypesInfo system. XAF uses it for creating UI and for all the metadata operations. Because of how XAF was designed and because of the way TypesInfo system was built, metadata modification could be done easily.
  2. By default, XAF supports two ORM framework, XPO and Entity/ In addition, it is possible to integrate a custom ORM system. To make this possible, a separate interface, the ITypeInfoSource, which holds all the type metadata is available.

UI + business logic <— TypesInfo –> XpoTypeInfoSource OR EFTypeInfoSource OR any ITypeInfoSource.

Now we know that the XpoTypeInfoSource will retrieve Type members for any class from XAF. Therefore, we only need to override the EnumsMembers method of the XpoTypeInfoSource to provide our own implementation! Bellow is an excerpt of this implementation you can find the rest in the sample at the end of the post.

public class XpandXpoTypeInfoSource : DevExpress.ExpressApp.DC.Xpo.XpoTypeInfoSource, ITypeInfoSource {

    void ITypeInfoSource.EnumMembers(TypeInfo info, EnumMembersHandler handler) {

        EnumMembers(info, handler);

        Type type = info.Type;

        if (TypeIsKnown(type)) {

            if (type.IsInterface) {

                EnumDCInterfaceMembers(info, handler);

            }

        }

    }

No doubt you too find this quick and simple? I always emphasize that XAF has 2 main advantages

  1. It is well architectured –> overridable.
  2. It is well architectured –> reusable.

And since it is overridable and reusable you can download and use the DynamicMemberAliasesForDC.zip Winking smile.

We are happy to read your input about this!. Remember that your questions are the best candidates for future posts.

P.S. : The eXpandFramework users only need to register the Core modules (see How to use an eXpand module with an existing XAF application)

Until next time, happy XAF’ing!

Updated 2/9/2013

In the next video, I demo how to create a calculated property in runtime.

Subscribe to XAF feed
Subscribe to community feed

5 comment(s)
Steven Rasmussen

Awesome!  Thanks for answering my question on your other post with this new article!

6 February, 2013
Steven Rasmussen

It looks like the download points to your previous posts zip file.  Is there supposed to be a different one for this article?

7 February, 2013
Apostolis Bekiaris (DevExpress)

My apologies, updated to DC version

7 February, 2013
Apostolis Bekiaris (DevExpress)

Update with a short show of demo at the end of the post

8 February, 2013
Naomi Kory

I am getting the following error when a runtime member is being added-

"Dictionary cannot be modified while it's being used by the ThreadSafeDataLayer. To avoid this exception, call the Session.CreateObjectTypeRecords method before using ThreadSafeDataLayer"

18 March, 2013

Please login or register to post comments.