Monday, November 2, 2009

Dynamic Types with WorldCreator source code is out

WorldCreator is a xaf module that provide dynamic persistent types for your application and runtime members for your existing classes. That means that you can define dynamic types at runtime through a UI (xaf views) save them in the database and let your imagination free !!!

Installation
Very simple you just register the selected assemblies bellow

image image

 

and add the required classes you want from .Persistent.BaseImpl

image

At my previous post IOC by BaseImpl I have explain the use of DevExpress.Persistent.BaseImpl assembly so in the same concept eXpand now has its own eXpand.Persistent.BaseImpl that will host a default implementation of persistent interfaces used from eXpand

image

As you can see at the above image there are to types of prefixes on those classes

Persistent—>Using those classes you describe your dynamic types
Extended-->Using those classes you add runtime types to your existent classes

I have already demo how you can model a domain at Yes Xaf can do it before lunch!!! so I am not going to repeat my self on that. Instead I will speak about some new features

Support for Custom attributes

As you see in the above image there is a PersistentMetaData namespace that hosts attributes. I did not implement all XPO,Xaf attributes

But its very easy to do so or to implement your own custom attribute, see for example PersistentCustomAttribute bellow

[DefaultProperty("PropertyName")]
public class PersistentCustomAttribute : PersistentAttributeInfo
{
    public PersistentCustomAttribute(Session session) : base(session) {
    }

    private string  _value;

    public PersistentCustomAttribute() {
    }
    private string _propertyName;
    public string PropertyName
    {
        get
        {
            return _propertyName;
        }
        set
        {
            SetPropertyValue("PropertyName", ref _propertyName, value);
        }
    }
    public string Value
    {
        get
        {
            return _value;
        }
        set
        {
            SetPropertyValue("Value", ref _value, value);
        }
    }
    public override AttributeInfo Create() {
        return new AttributeInfo(typeof(CustomAttribute).GetConstructor(new[] { typeof(string), typeof(string) }), PropertyName,Value);
    }
}

the trick is at create method, there you pass the constructor of the attribute you want to create and an array of arguments for that constructor and you are done!! One more attribute supported

so if anyone implement any more attributes I would be glad to host them in eXpand.

image

Inheritance
image

In the above image you see how you could extend your User class

You can inherit from Dynamic or existent class

Runtime member for existent Types

image

In the above image you can see how you can extend current user with an aggregated association collection.

Be carefull
If you create runtime members on existent classes and try to apply any validation rule on those members your application will throw an exception at start up. I have register an issue on that on DevExpress support so if you would like to implemented real soon from Dx please vote on it

After Dx implements that you can use the model to tell for which classes you want to describe their runtime member

image

WorldCreator is part of eXpand framework and you can get it here

Subscribe to XAF feed
Subscribe to community feed

DiggIt!
blog comments powered by Disqus