Friday, March 19, 2010

The AdditionalViewControlsProvider Module

 AdditionalViewControlsProvider is a module that it only knows how to display a given control in a given position . So one could easily define an interface for the parameters needed when this behavior is implemented as

public interface IAdditionalViewControlsRule:IConditionalLogicRule {

    string Message { get; set; }

    string MessagePropertyName { get; set; }

    Type DecoratorType { get; set; }

    Type ControlType { get; set; }

    AdditionalViewControlsProviderPosition AdditionalViewControlsProviderPosition { get; set; }

    bool UseSameIfFound { get; set; }


take a note that I inherit IConditionalLogicRule  thus logic engine can evaluate the IAdditionalViewControlsRule like it is a conditional rule meaning that is going to create all properties of conditionalLogic+ logic for my attributes, model , permission


Everything you see in the above image is automatically generated for you if you provide the require classes


the above classes implementation is just a property implementation without any logic at all see for example

[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]

public class AdditionalViewControlsAttribute : ConditionalLogicRuleAttribute,IAdditionalViewControlsRule


    public AdditionalViewControlsAttribute(string id,string message,


                                               additionalViewControlsProviderPosition, Type controlType,

                                           Type decoratorType,  string messagePropertyName, string normalCriteria, string emptyCriteria) : base(id,Nesting.Any,normalCriteria,emptyCriteria,ViewType.Any,

                                                                                                                                                          null) {

        Message = message;

        AdditionalViewControlsProviderPosition = additionalViewControlsProviderPosition;

        ControlType = controlType;

        DecoratorType = decoratorType;

        MessagePropertyName = messagePropertyName;



    public string Message { get; set; }

    public string MessagePropertyName { get; set; }

    public Type DecoratorType { get; set; }

    public Type ControlType { get; set; }

    public AdditionalViewControlsProviderPosition AdditionalViewControlsProviderPosition { get; set; }

    public bool UseSameIfFound { get; set; }


all the logic should be hosted in a ConditionalLogicRuleViewController derived class so for this case this class will look like

public abstract class AdditionalViewControlsRuleViewController :ConditionalLogicRuleViewController<IAdditionalViewControlsRule> {


    public override void ExecuteRule(LogicRuleInfo<IAdditionalViewControlsRule> logicRuleInfo, ExecutionContext executionContext) {

        if (logicRuleInfo.Active){

            IAdditionalViewControlsRule additionalViewControlsRule = logicRuleInfo.Rule;

            var calculator = new AdditionalViewControlsProviderCalculator(additionalViewControlsRule, logicRuleInfo.View.ObjectTypeInfo.Type);

            object control = Activator.CreateInstance(calculator.ControlsRule.ControlType);

            AddControl(control, logicRuleInfo, calculator, executionContext);



Also in order to control the default execution context for this module I did it like

public sealed partial class AdditionalViewControlsProviderAspNetModule : ConditionalLogicRuleProviderModuleBase<IAdditionalViewControlsRule>



    protected override bool IsDefaultContext(ExecutionContext context) {

        return context == ExecutionContext.ViewControlAdding;




In the next post I am going to speak how i inherit the conditionalmodule in order to implement the ModelartifactState module

Subscribe to XAF feed
Subscribe to community feed

blog comments powered by Disqus