AspectCore-Framework icon indicating copy to clipboard operation
AspectCore-Framework copied to clipboard

suggest:创建代理类类型时执行自定义操作。

Open wzd24 opened this issue 5 years ago • 1 comments

提议,添加一个配置项,以便在创建代理类时可执行一些自定义操作,如:

services.ConfigureDynamicProxy({
    c=>c.Interceptors.AddServiced<LogInterceptor>(
        m=>m.DeclaringType.Name.EndsWith("AppService"));
    c.OnGenerateProxy(context=>context.TypeBuilder.SetCustomAttribute(
        CustomAttributeBuildeUtils.DefineCustomAttribute(typeof(DynamicallyAttribute)););

  [NonAspect]
    public interface IAspectConfiguration
    {
        AspectValidationHandlerCollection ValidationHandlers { get; }

        InterceptorCollection Interceptors { get; }

        NonAspectPredicateCollection NonAspectPredicates { get; }

        bool ThrowAspectException { get; set; }

        IAspectConfiguration OnGenerateProxy(Action<GenerateProxyContext> configureAction);
    }

    public sealed class GenerateProxyContext
    {

        public TypeBuilder TypeBuilder { get; init; }

        public Type ServiceType { get; init; }

        public Type ImplementType { get; init; }

    }

wzd24 avatar Nov 13 '20 00:11 wzd24

不错的提议,考虑添加。

liuhaoyang avatar Dec 27 '20 17:12 liuhaoyang