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!
blog comments powered by Disqus