c# - Unity interception doesn't work as expected -
i use unity aop framework, doesn't work expected. please check code below.
container.registertype<iperson, person>(new interceptor<transparentproxyinterceptor>(), new interceptionbehavior<logginginterceptionbehavior>(), new injectionconstructor(container.resolve<iplay>(), container.resolve<ieat>())); var person = container.resolve<iperson>(); person.play(); person.eat(); ((ianimal)person).sleep(); console.read(); public imethodreturn invoke(imethodinvocation input, getnextinterceptionbehaviordelegate getnext) { console.writeline(string.format("invoking method {0} begin", input.methodbase)); var result = getnext()(input, getnext); if (result.exception != null) { console.writeline("{0} throws exception", input.methodbase); } else { console.writeline(string.format("invoking method {0} end", input.methodbase)); } return result; }
when container.resolve() , ((ianimal)person) run, behavior executed, , print out
invoking method system.type gettype() begin
invoking method system.type gettype() end
i want log execute when call method explicitly. how prevent it?
Comments
Post a Comment