here's situation:
/// <summary> /// business logic class. /// </summary> public class businessclasswithinterceptor : businessclass, ibusinessclass { /// <summary> /// initializes new instance of <see cref="businessclasswithoutinterceptor"/> class. /// </summary> /// <param name="logger">the logger.</param> public businessclasswithinterceptor(logger logger) : base(logger) { } /// <summary> /// displays cows. /// </summary> public void displayallcows() { this.logger.write("displaying cows:"); var repository = new cowrepository(); foreach (cowentity cow in repository.getallcows()) { this.logger.write(" " + cow); } } /// <summary> /// inserts normande. /// </summary> public void insertnormande(int id, string name) { this.displayallcows(); var repository = new cowrepository(); repository.insertcow(new cowentity { id = id, name = name, origin = coworigin.normandie }); } }
with castle windsor, class configured intercepted interceptor:
/// <summary> /// interceptor logging business methods. /// </summary> public class businessloginterceptor : iinterceptor { /// <summary> /// intercepts specified invocation. /// </summary> /// <param name="invocation">the invocation.</param> public void intercept(iinvocation invocation) { logger logger = ((ibusinessclass)invocation.invocationtarget).logger; var parameters = new stringbuilder(); parameterinfo[] methodparameters = invocation.method.getparameters(); (int index = 0; index < methodparameters.length; index++) { parameters.appendformat("{0} = {1}", methodparameters[index].name, invocation.arguments[index]); if (index < methodparameters.length - 1) { parameters.append(", "); } } logger.format("calling {0}( {1} )", invocation.method.name, parameters.tostring()); invocation.proceed(); logger.format("exiting {0}", invocation.method.name); } }
the issue takes place during call insertnormande. call insertnormande intercepted, call displayallcows in insertnormande not intercepted...
it bothers me.
is there way achieve interception in scenario ?
i don't think there's easy way of doing it... method calls internal class can't intercepted, since don't go through proxy.
you achieve logging of methods other means, such aop framework postsharp
Comments
Post a Comment