Created
April 7, 2011 15:34
-
-
Save rauhryan/908017 to your computer and use it in GitHub Desktop.
ObjectDef example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NavigationVisitor : IBehaviorVisitor | |
{ | |
private readonly IConfigurationObserver _observer; | |
private readonly ListDependency _policies = new ListDependency(typeof(IEnumerable<IMenuPolicy>)); | |
public NavigationVisitor(IConfigurationObserver observer) | |
{ | |
_observer = observer; | |
} | |
public void VisitBehavior(BehaviorChain chain) | |
{ | |
if(chain.FirstCall().Method.HasAttribute<NavigationAttribute>() && chain.HasInput()) | |
{ | |
ActionCall actionCall = chain.FirstCall(); | |
var attr = actionCall.Method.GetAllAttributes<NavigationAttribute>(); | |
foreach (var navigationAttribute in attr) | |
{ | |
_observer.RecordCallStatus(actionCall, "NavigationVisitor: Matched on has navigation attribute filter"); | |
Type ruleType = typeof(ContextualMenuRule<>).MakeGenericType( | |
chain.InputType()); | |
var depDef = _policies.AddType(typeof(MenuPolicy<>).MakeGenericType(chain.InputType())); | |
var ruleDef = new ObjectDef(ruleType); | |
ruleDef.Child(typeof(ActionCall), actionCall); | |
ruleDef.Child(typeof(NavigationAttribute), navigationAttribute); | |
depDef.Dependencies.Add(new ConfiguredDependency() | |
{ | |
DependencyType = typeof(IMenuRule<>).MakeGenericType(chain.InputType()), | |
Definition = ruleDef | |
}); | |
} | |
} | |
} | |
public IEnumerable<ObjectDef> AllMenus | |
{ | |
get | |
{ | |
return _policies.Items; | |
} | |
} | |
public void Register(Action<Type, ObjectDef> register) | |
{ | |
var cacheDef = new ObjectDef(typeof (MenuRegistry)); | |
cacheDef.Dependencies.Add(_policies); | |
register(typeof (IMenuRegistry), cacheDef); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment