seesharper / LightInject.Interception

LightInject.Interception supports Aspect Oriented Programming through proxy-based method interceptors.
11 stars 7 forks source link

This package is not compatible with Annotations #32

Closed kemsky closed 2 years ago

kemsky commented 2 years ago

LightInject.Interception.ProxyBuilder.ImplementAllConstructorsFromBaseClass method does not copy original attributes, as a result AnnotatedConstructorDependencySelector can not find InjectAttribute's in proxy constructor:

                foreach (var parameterInfo in constructorInfo.GetParameters())
                {
                    constructorBuilder.DefineParameter(
                        parameterInfo.Position + 1,
                        parameterInfo.Attributes,
                        parameterInfo.Name); // no custom attributes anymore, maybe use SetCustomAttribute and copy
                }

Maybe something like this will work:

                foreach (var parameterInfo in constructorInfo.GetParameters())
                {
                    var parameterBuilder = constructorBuilder.DefineParameter(
                        parameterInfo.Position + 1,
                        parameterInfo.Attributes,
                        parameterInfo.Name);

                    foreach (var customAttribute in parameterInfo.CustomAttributes)
                    {
                        parameterBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(customAttribute));
                    }
                }
kemsky commented 2 years ago

@seesharper, when do you plan to publish version 2.0.4?

seesharper commented 2 years ago

Just released 👍 https://www.nuget.org/packages/LightInject.Interception/2.0.4