/// <summary> /// Executes before initiating the service instance. /// </summary> /// <param name="contractType"></param> /// <param name="serviceName"></param> /// <returns></returns> protected InvocationInfo BeforeInvoke(Type contractType, string serviceName) { var factory = _internalsm.GetServiceFactory(); BaseServiceInfo serviceInfo = factory.GetServiceInfo(contractType, serviceName); if (serviceInfo == null) { return(default(InvocationInfo)); } //Invoke if there are any decorators. if (DecoratorManager.GlobalDecorators.Count > 0 || (serviceInfo.Decorators != null && serviceInfo.Decorators.Length > 0)) { ServiceCallContext callContext = ServiceCallContext.Create(contractType, serviceInfo.ServiceType, this); InvokeDecorator(callContext, InvocationCase.Before, serviceInfo.Decorators); return(new InvocationInfo() { ServiceInfo = serviceInfo, ServiceCallContext = callContext }); } return(new InvocationInfo() { ServiceInfo = serviceInfo }); }
private void AfterInvoke(ServiceCallContext context, IEnumerable <DecoratorAttribute> decorators) { foreach (var decorator in decorators) { decorator.OnAfterInvoke(context); } }
/// <summary> /// Executes decorator /// </summary> /// <param name="context">Specify the service call context object.</param> /// <param name="case"></param> /// <param name="localDecorators">Specify decorators of the contract.</param> public void Execute(ServiceCallContext context, InvocationCase @case, IEnumerable <DecoratorAttribute> localDecorators) { switch (@case) { case InvocationCase.Before: /*Invoke first global decorators and then local decorators*/ if (GlobalDecorators != null && GlobalDecorators.Count > 0) { BeforeInvoce(context, GlobalDecorators); } if (localDecorators != null) { BeforeInvoce(context, localDecorators); } break; case InvocationCase.After: /*Invoke first global decorators and then local decorators*/ if (GlobalDecorators != null && GlobalDecorators.Count > 0) { AfterInvoke(context, GlobalDecorators); } if (localDecorators != null) { AfterInvoke(context, localDecorators); } break; } }
/// <summary> /// Executes after initiating the service instance. /// </summary> /// <param name="objectInstance"></param> /// <param name="context"></param> /// <param name="localDecorators"></param> protected void AfterInvoke(object objectInstance, ServiceCallContext context, DecoratorAttribute[] localDecorators) { //Invoke if there are any decorators. if (context != null && (DecoratorManager.GlobalDecorators.Count > 0 || (localDecorators != null && localDecorators.Length > 0))) { context.ServiceInstance = objectInstance; InvokeDecorator(context, InvocationCase.After, localDecorators); } }
private void InvokeDecorator(ServiceCallContext context, InvocationCase @case, IEnumerable <DecoratorAttribute> localDecorators) { DecoratorManager.Execute(context, @case, localDecorators); }
/// <summary> /// Executes after invocation of the service, in this event, service instance /// is accessible so that you can inject the data or dependencies that can be set through properties/fields. /// </summary> /// <param name="context">The context of the service</param> public virtual void OnAfterInvoke(ServiceCallContext context) { }
/// <summary> /// Executes before invocation of the service. /// </summary> /// <param name="context">The context of the service</param> public virtual void OnBeforeInvoke(ServiceCallContext context) { }