I'm trying to get an authorization rule to work with multple objects. Within the Execute method, I use the Parent property derived from the BusinessBase object.
protected override void Execute(AuthorizationContext context) { if (_roles.Count > 0) { FullyLoadedCost flc = context.Target as FullyLoadedCost; if (flc != null) { FullyLoadedCostList fl = flc.Parent as FullyLoadedCostList; if (fl != null && fl.WhatIf) { context.HasPermission = true; return; } }
...
In the current example this is specific to the FullyLoadedCost object.
I'd like to make the authorization rule more generic.
I can use an interface for the boolean WhatIf property, but I can't
quite figure how to get BusinessBase<T> out of the context Target property.
The below doesn't work as it is requiring T to be defined.
Csla.BusinessBase<T> myBase = context.Target as Csla.BusinessBase<T>;
Perhaps I could do this if the AuthorizationRule was generic itself.
Any ideas?
Hi Curelom,
Have a look at NoDuplicates business rule. You can find it at http://cslagenfork.codeplex.com/
Hi,
You could also look at Csla.Rules.RuleExtensions and how it "wrap" a lambda expression into a rule.
I suppose you could create generic Authz rule with a lamda "WhatIf". (I haven't tried this on Authz rules myself).
Copyright (c) Marimer LLC