Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

structuremap - What's the simplest way to intercept a method call for added functionality? -


suppose have repository returns list of posts. repository interface has getall() method suggests.

now in keeping theory shouldn't putting domain logic in repository, want intercept calls concrete getall() method such can add following logic getall() result:

return getall().orderbydescending(p => p.posted).tolist(); 

the reason want intercept because (1) don't want have client remember call extension method (orderbydescending or useless wrapper of that), want called every time , (2) don't want have concrete implementations have remember order getall() result - want logic in single place external repository.

what's easiest way this?

i'm using structuremap if can intercept might low cost option. don't think sm intercepts method calls, creation of object instance?

do need go proxy or mixin pattern? need go all-in castle dynamic proxy? or there another method should consider or perhaps combination?

i'm interested in concrete suggestion particular example above. i'm novice aop please gentle.

went dynamicproxy option. easier use thought.

all took using castle.dynamicproxy; reference...

a bit of iinterceptor...

public class postrepointerceptor : iinterceptor {     public void intercept(iinvocation invocation)     {         invocation.proceed();          if (invocation.method.name.equals("getall", stringcomparison.invariantcultureignorecase))             invocation.returnvalue = this.getmodifiedgetallresult(invocation.returnvalue);     }      private object getmodifiedgetallresult(object getallresult)     {         return post.getorderedposts((ilist<post>)getallresult);     } } 

two new lines in structuremap config:

    public reporegistry()     {         var pg = new proxygenerator();          for<ipostrepository>()             .enrichallwith(z => pg.createinterfaceproxywithtarget<ipostrepository>(z, new postrepointerceptor()));     } 

..and it's done. getall() behaves how want. can still use interfaces way i'm familar , i've kept dry , decoupled ddd.

thanks sam , andre.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -