Tuesday, November 24, 2009

Xaf Tip #11 MVC architecture to overcome cyclic reference

Cyclic reference is probably due to a flaw in design.

So what? We are not perfect

But we use Xaf, a model driven Application Framework from Devexpress and we can take advantage of that architecture so to overcome cyclic reference problems.

I think an example is the most appropriate here.

eXpand has a module called AdditionalViewControlsProvider , it can provide as the name says controls to views by setting some values on the model

image

image

and since its an eXpand module it references eXpand.ExpressApp assembly (core)

after I release AdditionalViewControlsProvider I release also PropertyPathFilters which is using AdditionalViewControlsProvider module to display the extra criteria

image

but is hosted at eXpand.ExpressApp assembly (core) !!!

How in the heck did I do that?

Simple I knew that AdditionalViewControlsProvider is sawing controls only if message is set to something, so even if core did not have a reference to AdditionalViewControlsProvider I could set that attribute to the value i wanted like

ClassInfoNodeWrapper wrapper = GetClassInfoNodeWrapper();
DictionaryNode dictionaryNode = wrapper.Node.FindChildNode("AdditionalViewControls");
dictionaryNode.SetAttribute("Message",text);

and when I reference both eXpand.ExpressApp assembly (core) and AdditionalViewControlsProvider everything will work as expected.

And even if I try to use propertypathfilters without AdditionalViewControlsProvider I could easily throw a warning like

private void checkIfAdditionalViewControlsModuleIsRegister(){
    ClassInfoNodeWrapper wrapper = GetClassInfoNodeWrapper();
    DictionaryNode node = wrapper.Node.FindChildNode("AdditionalViewControls");
    if (node== null){
        throw new UserFriendlyException(new Exception("AdditionalViewControlsProvider module not found"));
    }
}
Technorati Tags:

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Thursday, November 19, 2009

BDD for Dynamic Types with mspec

This one will be my 2nd post about mspec. The first on can be found here.

I am still newbie in Mspec crazy syntax!! but have done a lot of TDD (after all BDD is TDD) , so my 1st effort of using mspec to describe all specifications (=expression of behaviors) for dynamic types module, along with some refactoring produced the following output

------ Test started: Assembly: eXpand.Tests.dll ------
ModuleCreator, When Creating Dynamic Module
»
should return a list of module base descenants
ExistentTypesMemberCreator, When Creating ExistentTypes CoreMembers that exist already
» should not throw any exceptions
ExistentTypesMemberCreator, When Creating ExistentTypes CoreMembers
»
should find that member through xpdictionary
» should create typedattributes ExistentTypesMemberCreator,
When Creating ExistentTypes ReferenceMembers
» should find that member through xpdictionary
» should create typedattributes ExistentTypesMemberCreator,
When Creating ExistentTypes CollectionMembers
» should find that member through xpdictionary
» should create typedattributes WorldCreatorModule,
When SettingUp Module
» should contain dynamic modules within Application Modules collection
» should not load modelDiffs from dynamic assemblies
» should create Existent Classes Member WorldCreatorModule,
When Updating Model
» should display owner column to extended members list view
» should remove dynamic assemblies from Assemblies image Node WorldCreatorModule,
When Application Setup Is Completed
» should merge any mergable dynamic type
PersistentClassInfoTypeBuilder specs, When Creating An Assembly
» should Create An Assembly In Current AppDomain
PersistentClassInfoTypeBuilder specs, When Defining A DynamicType
» should Create A Dynamic Type
» should have A Constructor with Session as parameter
PersistentClassInfoTypeBuilder specs, When Requesting A Property With Reflection
» should find a property
» should be of Correct Type
PersistentClassInfoTypeBuilder specs, When Invoking A Property
» should have value
PersistentClassInfoTypeBuilder specs, When Creating A reference Property of dynamic type
» should find the property thourgh reflection
» should be ofthe correct referenced type
PersistentClassInfoTypeBuilder specs, When Creating A reference Property of existent type
» should find the property thourgh reflection
» should be ofthe correct referenced type
PersistentClassInfoTypeBuilder specs, When Invoking A Dynamic Reference Property
» should have the correct value
PersistentClassInfoTypeBuilder specs, When Creating A Collection Property
» should find the propertyInfo through reflection
PersistentClassInfoTypeBuilder specs, When Invoking A Dynamic Collection Property
» should not have value
PersistentClassInfoTypeBuilder specs, When Applying Attributes To Properties
» should be discovarable thourgh reflection
PersistentClassInfoTypeBuilder specs, When Applying Attributes To Dynamic Classes
» should be discoverable through reflection
PersistentClassInfoTypeBuilder specs, When Associating 1 DynamicType With 1 Existent
» should create 2 types In Current domain
PersistentClassInfoTypeBuilder specs, When Changing A Dynamic property
» should raize changed event
PersistentClassInfoTypeBuilder specs, When Dynamic Type Inherits Existent Type
» should have as base Class the existent one
PersistentClassInfoTypeBuilder specs, When Dynamic Type inherits a Dynamic type
» should have as base class the dynamic one
PersistentClassInfoTypeBuilder specs, When DynamicType Implement An Interface
» should be Discoverable thourgh reflection
» should create non existent properties
PersistentClassInfoTypeBuilder specs, When Creating Types In A Non Xaf Context
» should create a Dynamic Type
XpoObjectMerger, When Merging Dynamic Types
» should updateXpdictionary Schema for each type
» should call an update sql statement
» should create an ObjectType Column to Parent
36 passed, 0 failed, 1 skipped, took 9,59 seconds (MSpec).

What do you think of the above specs? Can you understand all functionality supported by the dynamics types module (WorldCreator) from the above specs?

Want to see some code for the spec “When Creating A reference Property of dynamic type”?

image
Is that descriptive or what?
I suggest you use TestDriven.Net to run your specs since it provides support debugging and TypeMock out of the box
And some more mspec goodies from @agross.
Download A fully working app covered with mspec for your reference

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

eXpand source code has moved to GitHub

why we moved to GitHub?

The main reason is speed. With Git u get the chance to work locally make your operations at your H/D and push any of those changes to GitHub anytime you want. And even that is  faster cause Git does not rely of Differences (Deltas) to work, it is just sending snapshot of the current file system.

Another reason is that the tools for Gitting are pretty stable right now so there is no need to master Unit Shell in order to use it. So you can find TortoiseGit which is TortosieSvn port, Also GitExtensions are doing a very good job with Git – Visual studio integration.

Another very impressive feature of GitHub is the collaboration between users. For example you may want to develop upon eXpand in your own way and without being a member of the project and git hub gives a cool way to visualize that

see Say hello to the Network Graph Visualizer

or you may want at future to merge with eXpand main line or another developer line , its entirely up to u.

And for those of you that do not want or care about using Git in your daily work, GitHub provides a compressed archive of sources to download and use by just clicking a download link Dutton.

see also how

How to get eXpand latest version
Technorati Tags: ,

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Monday, November 16, 2009

Dynamic types in any application?

WorldCreator a module designed to work with Xaf can really work without it!!!!

Suppose you have a non xaf application and you use Xpo as your dataLayer and you want dynamic types then WorldCreator can for sure help you.

You just reference WorldCreator and eXpand.BaseImpl assemblies and use an approach similar to the specs bellow

[Test]
public void Can_Create_Types_In_A_Non_Xaf_Context() {
    new PersistentClassInfo(Session.DefaultSession){Name = "Test"}.Save();
    var typeCreator =
        new TypeCreator(
            new TypesInfo(new List<Type> {
                                             typeof (PersistentClassInfo),
                                             typeof (ExtendedCollectionMemberInfo),
                                             typeof (ExtendedReferenceMemberInfo),
                                             typeof (ExtendedCoreTypeMemberInfo),
                                             typeof (InterfaceInfo)
                                         }), new UnitOfWork(Session.DefaultSession.DataLayer));

    Type dynamicModule = typeCreator.GetDynamicModule();

    Assert.IsNotNull(dynamicModule);
    Assert.IsNotNull(dynamicModule.Assembly.GetTypes().Where(type => type.Name=="Test").FirstOrDefault());
}
Technorati Tags: ,

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Tuesday, November 10, 2009

Dynamic Types and Interfaces

Its now possible to implement existent interfaces for your dynamic types .

How?

Setup your InterfaceSources at your model

image

Populate them through InterfaceInfo Listview

image

and make your dynamic classes to implement them

image

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Monday, November 9, 2009

Filtering a listview of objects according to their childs

 The Problem 1
A common requirement in any OOP application is the ability to filter a listview of objects according to their childs in whatever level they belong.

eXpand can solve the above by the use of propertypath filters. So in an Customer—>Orders--->OrderLines relationship

the filter bellow are enough to filter your customer list view according to any property value of their Orders child collection

image

with the one bellow you can filter customer list view by any property value of orderlines collection of customers orders collection

image

In the video bellow i demo

1. the above functionality that is hosted at eXpand.ExpresApp assembly,
2. eXpand.ViewVariants module for creating views without the model editor (that is badly needed now that we can have multiple filters on a view)
3. A more complex filtering scenario using recursive filtering (provided by eXpand.TreeListEditors.Win) and a combination of filtering

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

Tuesday, November 3, 2009

Dynamic Type Merging

I hope you all vote on DeveExrpess Issue that will allow us to validate runtime extended existent types. But even if you did not there is an alternative way that my friend Emilio shared with us.

I want to add runtime members for my existent Customer class for which records already exist in the DB and also use the validation system

You can create a new dynamic type that inherit your customer class decorate it with the MapInheritance attribute and set the MergedObjectType same as BaseType

Download working sample app with source code here

Subscribe to XAF feed
Subscribe to community feed

DiggIt!

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!