├── .gitattributes
├── .github
└── workflows
│ ├── build-ci.yml
│ └── build-pr-ci.yml
├── .gitignore
├── AspectCore-Framework.sln
├── LICENSE
├── NuGet.config
├── README.md
├── benchmark
├── AspectCore.Core.Benchmark
│ ├── AspectCore.Core.Benchmark.csproj
│ ├── Benchmarks
│ │ └── GetTaskResultBenchmarks.cs
│ └── Program.cs
└── AspectCore.Extensions.Reflection.Benchmark
│ ├── AspectCore.Extensions.Reflection.Benchmark.csproj
│ ├── Benchmarks
│ ├── ConstructorReflectorBenchmarks.cs
│ ├── CustomAttributeReflectorBenchmarks.cs
│ ├── FieldReflectorBenchmarks.cs
│ ├── MethodReflectorBenchmarks.cs
│ └── PropertyReflectorBenchmarks.cs
│ ├── Fakes
│ ├── ConstructorFakes.cs
│ ├── FieldFakes.cs
│ ├── MethodFakes.cs
│ └── PropertyFakes.cs
│ └── Program.cs
├── build
├── aspectcore.snk
├── common.props
├── sign.props
└── version.props
├── docs
├── 0.AOP简单介绍.md
├── 1.使用指南.md
├── injector.md
├── reflection-extensions.md
└── reflection.md
├── sample
├── AspectCore.Extensions.AspectScope.Sample
│ ├── AspectCore.Extensions.AspectScope.Sample.csproj
│ └── Program.cs
├── AspectCore.Extensions.Autofac.Sample
│ ├── AspectCore.Extensions.Autofac.Sample.csproj
│ ├── MethodExecuteLoggerInterceptor.cs
│ └── Program.cs
├── AspectCore.Extensions.DataAnnotations.Sample
│ ├── AspectCore.Extensions.DataAnnotations.Sample.csproj
│ ├── IAccountService.cs
│ ├── Program.cs
│ └── RegisterInput.cs
└── AspectCore.Extensions.DependencyInjection.ConsoleSample
│ ├── AspectCore.Extensions.DependencyInjection.ConsoleSample.csproj
│ └── Program.cs
├── src
├── AspectCore.Abstractions
│ ├── AspectCore.Abstractions.csproj
│ ├── Configuration
│ │ ├── AspectPredicate.cs
│ │ ├── AspectValidationHandlerCollection.cs
│ │ ├── IAspectConfiguration.cs
│ │ ├── InterceptorCollection.cs
│ │ ├── InterceptorFactory.cs
│ │ └── NonAspectPredicateCollection.cs
│ ├── DependencyInjection
│ │ ├── ConfigurationExtensions.cs
│ │ ├── Definitions
│ │ │ ├── DelegateServiceDefinition.cs
│ │ │ ├── InstanceServiceDefinition.cs
│ │ │ ├── ServiceDefinition.cs
│ │ │ └── TypeServiceDefinition.cs
│ │ ├── FromServiceContextAttribute.cs
│ │ ├── ILifetimeServiceContext.cs
│ │ ├── IManyEnumerable.cs
│ │ ├── IPropertyInjector.cs
│ │ ├── IPropertyInjectorFactory.cs
│ │ ├── IScopeResolverFactory.cs
│ │ ├── IServiceContext.cs
│ │ ├── IServiceResolveCallback.cs
│ │ ├── IServiceResolver.cs
│ │ ├── ITransientServiceAccessor.cs
│ │ ├── Lifetime.cs
│ │ ├── LifetimeServiceContextExtensions.cs
│ │ ├── ServiceContextExtensions.cs
│ │ ├── ServiceProviderExtensions.cs
│ │ └── ServiceResolverExtensions.cs
│ ├── DynamicProxy
│ │ ├── AbstractInterceptor.cs
│ │ ├── AbstractInterceptorAttribute.cs
│ │ ├── AspectActivatorContext.cs
│ │ ├── AspectContext.cs
│ │ ├── AspectDelegate.cs
│ │ ├── AspectInvalidCastException.cs
│ │ ├── AspectInvalidOperationException.cs
│ │ ├── AspectInvocationException.cs
│ │ ├── AspectValidationContext.cs
│ │ ├── AspectValidationDelegate.cs
│ │ ├── AsyncAspectAttribute.cs
│ │ ├── DelegateInterceptor.cs
│ │ ├── DynamicallyAttribute.cs
│ │ ├── IAdditionalInterceptorSelector.cs
│ │ ├── IAspectActivator.cs
│ │ ├── IAspectActivatorFactory.cs
│ │ ├── IAspectBuilder.cs
│ │ ├── IAspectBuilderFactory.cs
│ │ ├── IAspectCaching.cs
│ │ ├── IAspectCachingProvider.cs
│ │ ├── IAspectContextFactory.cs
│ │ ├── IAspectValidationHandler.cs
│ │ ├── IAspectValidator.cs
│ │ ├── IAspectValidatorBuilder.cs
│ │ ├── IInterceptor.cs
│ │ ├── IInterceptorCollector.cs
│ │ ├── IInterceptorSelector.cs
│ │ ├── IProxyGenerator.cs
│ │ ├── IProxyTypeGenerator.cs
│ │ ├── IServiceInstanceAccessor.cs
│ │ ├── NonAspectAttribute.cs
│ │ ├── Parameters
│ │ │ ├── IParameterInterceptor.cs
│ │ │ ├── IParameterInterceptorSelector.cs
│ │ │ ├── Parameter.cs
│ │ │ ├── ParameterAspectContext.cs
│ │ │ ├── ParameterAspectDelegate.cs
│ │ │ ├── ParameterCollection.cs
│ │ │ ├── ParameterExtensions.cs
│ │ │ ├── ParameterInterceptorAttribute.cs
│ │ │ ├── ReturnParameter.cs
│ │ │ └── ReturnParameterInterceptorAttribute.cs
│ │ └── ServiceInterceptorAttribute.cs
│ └── Properties
│ │ └── AssemblyInfo.cs
├── AspectCore.Core
│ ├── AspectCore.Core.csproj
│ ├── Configuration
│ │ ├── AspectConfiguration.cs
│ │ ├── Extensions
│ │ │ ├── AspectValidationHandlerCollectionExtensions.cs
│ │ │ ├── InterceptorCollectionExtensions.cs
│ │ │ ├── NonAspectsCollectionExtensions.cs
│ │ │ └── StringExtensions.cs
│ │ ├── InterceptorFactories
│ │ │ ├── DelegateInterceptorFactory.cs
│ │ │ ├── ServiceInterceptorFactory.cs
│ │ │ └── TypeInterceptorFactory.cs
│ │ └── Predicates.cs
│ ├── DependencyInjection
│ │ ├── ConstructorCallSiteResolver.cs
│ │ ├── EnumerableServiceDefintion.cs
│ │ ├── Extensions
│ │ │ ├── LinkedListExtensions.cs
│ │ │ ├── ServiceContainerBuildExtensions.cs
│ │ │ └── ServiceDefinitionExtensions.cs
│ │ ├── IServiceResolveCallbackProvider.cs
│ │ ├── LifetimeServiceContext.cs
│ │ ├── ManyEnumerable.cs
│ │ ├── PropertyInjector.cs
│ │ ├── PropertyInjectorCallback.cs
│ │ ├── PropertyInjectorFactory.cs
│ │ ├── PropertyResolver.cs
│ │ ├── PropertyResolverSelector.cs
│ │ ├── ProxyServiceDefinition.cs
│ │ ├── ScopeResolverFactory.cs
│ │ ├── ServiceCallSiteResolver.cs
│ │ ├── ServiceContext.cs
│ │ ├── ServiceResolver.cs
│ │ ├── ServiceTable.cs
│ │ ├── ServiceValidator.cs
│ │ └── TransientServiceAccessor.cs
│ ├── DynamicProxy
│ │ ├── AspectActivator.cs
│ │ ├── AspectActivatorFactory.cs
│ │ ├── AspectBuilder.cs
│ │ ├── AspectBuilderFactory.cs
│ │ ├── AspectCaching.cs
│ │ ├── AspectCachingProvider.cs
│ │ ├── AspectContext.Runtime.cs
│ │ ├── AspectContextFactory.cs
│ │ ├── AspectValidator.cs
│ │ ├── AspectValidatorBuilder.cs
│ │ ├── AttributeAdditionalInterceptorSelector.cs
│ │ ├── AttributeInterceptorSelector.cs
│ │ ├── ConfigureInterceptorSelector.cs
│ │ ├── Extensions
│ │ │ ├── AspectContextRuntimeExtensions.cs
│ │ │ ├── AspectValidatorExtensions.cs
│ │ │ └── ProxyGeneratorExtensions.cs
│ │ ├── InterceptorCollector.cs
│ │ ├── InterceptorSelectorEqualityComparer.cs
│ │ ├── Parameters
│ │ │ ├── EnableParameterAspectExtensions.cs
│ │ │ ├── EnableParameterAspectInterceptor.cs
│ │ │ ├── NotNullAttribute.cs
│ │ │ ├── ParameterAspectInvoker.cs
│ │ │ └── ParameterInterceptorSelector.cs
│ │ ├── ProxyGenerator.cs
│ │ ├── ProxyGeneratorBuilder.cs
│ │ ├── ProxyTypeGenerator.cs
│ │ └── ValidationHandlers
│ │ │ ├── AttributeAspectValidationHandler.cs
│ │ │ ├── CacheAspectValidationHandler.cs
│ │ │ ├── ConfigureAspectValidationHandler.cs
│ │ │ └── OverwriteAspectValidationHandler.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── Utils
│ │ ├── ActivatorUtils.cs
│ │ ├── ArrayUtils.cs
│ │ ├── MethodUtils.cs
│ │ ├── NoSyncContextScope.cs
│ │ ├── PropertyInjectionUtils.cs
│ │ ├── ProxyGeneratorUtils.cs
│ │ ├── ReflectionUtils.cs
│ │ └── TaskUtils.cs
├── AspectCore.Extensions.AspNetCore
│ ├── AspectCore.Extensions.AspNetCore.csproj
│ ├── Extensions
│ │ ├── AspectContextExtensions.cs
│ │ ├── ConfigurationExtensions.cs
│ │ └── ServiceCollectionExtensions.cs
│ ├── Filters
│ │ └── ModelStateAdapterAttribute.cs
│ ├── Http
│ │ ├── ExecutionContextHelper.cs
│ │ └── HttpContextFactory.cs
│ └── Interceptors
│ │ ├── MethodExecuteLoggerInterceptor.cs
│ │ └── ModelBindingAdapterAttribute.cs
├── AspectCore.Extensions.AspectScope
│ ├── AspectCore.Extensions.AspectScope.csproj
│ ├── IAspectScheduler.cs
│ ├── IScopeInterceptor.cs
│ ├── SchedulerHelpers.cs
│ ├── Scope.cs
│ ├── ScopeAspectBuilderFactory.cs
│ ├── ScopeAspectContext.cs
│ ├── ScopeAspectContextFactory.cs
│ ├── ScopeAspectScheduler.cs
│ ├── ScopeInterceptorAttribute.cs
│ └── ServiceContainerExtensions.cs
├── AspectCore.Extensions.Autofac
│ ├── ActivationResolveMiddleware.cs
│ ├── AspectCore.Extensions.Autofac.csproj
│ ├── AutofacScopeResolverFactory.cs
│ ├── AutofacServiceResolver.cs
│ ├── ContainerBuilderExtensions.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── RegistrationExtensions.cs
├── AspectCore.Extensions.Configuration
│ ├── AspectCore.Extensions.Configuration.csproj
│ ├── Attributes
│ │ ├── ConfigurationBindingAttribute.cs
│ │ ├── ConfigurationMetadataAttribute.cs
│ │ └── ConfigurationValueAttribute.cs
│ ├── ConfigurationBindResolveCallback.cs
│ ├── ConfigurationBindType.cs
│ ├── IConfigurationMetadataProvider.cs
│ └── ServiceContainerExtensions.cs
├── AspectCore.Extensions.DataAnnotations
│ ├── AnnotationDataValidator.cs
│ ├── AnnotationPropertyValidator.cs
│ ├── AspectCore.Extensions.DataAnnotations.csproj
│ └── ServiceContainerExtensions.cs
├── AspectCore.Extensions.DataValidation
│ ├── AspectContextExtensions.cs
│ ├── AspectCore.Extensions.DataValidation.csproj
│ ├── DataMetaData.cs
│ ├── DataState.cs
│ ├── DataStateFactory.cs
│ ├── DataValidationContext.cs
│ ├── DataValidationError.cs
│ ├── DataValidationErrorCollection.cs
│ ├── DataValidationInterceptorAttribute.cs
│ ├── DataValidationState.cs
│ ├── IDataState.cs
│ ├── IDataStateFactory.cs
│ ├── IDataStateProvider.cs
│ ├── IDataValidator.cs
│ ├── IPropertyValidator.cs
│ ├── PropertyMetaData.cs
│ ├── PropertyValidationContext.cs
│ └── SkipValidationAttribute.cs
├── AspectCore.Extensions.DependencyInjection
│ ├── AspectCore.Extensions.DependencyInjection.csproj
│ ├── DynamicProxyServiceProviderFactory.cs
│ ├── MsdiScopeResolverFactory.cs
│ ├── MsdiServiceResolver.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ServiceCollectionAddExtensions.cs
│ ├── ServiceCollectionBuildExtensions.cs
│ ├── ServiceCollectionExtensions.cs
│ ├── ServiceCollectionToServiceContextExtensions.cs
│ ├── ServiceContextProviderFactory.cs
│ ├── ServiceScope.cs
│ ├── ServiceScopeFactory.cs
│ ├── ServiceValidator.cs
│ └── SupportRequiredService.cs
├── AspectCore.Extensions.Hosting
│ ├── AspectCore.Extensions.Hosting.csproj
│ └── HostBuilderExtensions.cs
├── AspectCore.Extensions.LightInject
│ ├── AspectCore.Extensions.LightInject.csproj
│ ├── ContainerBuilderExtensions.cs
│ ├── LightInjectExtensions.cs
│ ├── LightInjectScopeResolverFactory.cs
│ └── LightInjectServiceResolver.cs
├── AspectCore.Extensions.Reflection
│ ├── AspectCore.Extensions.Reflection.csproj
│ ├── CallOptions.cs
│ ├── ConstructorReflector.OpenGeneric.cs
│ ├── ConstructorReflector.cs
│ ├── CustomAttributeReflector.cs
│ ├── Emit
│ │ ├── ILGeneratorExtensions.cs
│ │ └── IndexedLocalBuilder.cs
│ ├── Extensions
│ │ ├── CustomAttributeExtensions.cs
│ │ ├── InternalExtensions.cs
│ │ ├── MethodExtensions.cs
│ │ ├── ParameterInfoExtensions.cs
│ │ ├── ReflectorExtensions.cs
│ │ └── TypeExtensions.cs
│ ├── Factories
│ │ ├── ConstructorReflector.Factory.cs
│ │ ├── CustomAttributeReflector.Factory.cs
│ │ ├── FieldReflector.Factory.cs
│ │ ├── MethodReflector.Factory.cs
│ │ ├── ParameterReflector.Factory.cs
│ │ ├── PropertyReflector.Factory.cs
│ │ └── TypeReflector.Factory.cs
│ ├── FieldReflector.Enum.cs
│ ├── FieldReflector.OpenGeneric.cs
│ ├── FieldReflector.Static.cs
│ ├── FieldReflector.cs
│ ├── ICustomAttributeReflectorProvider.cs
│ ├── IParameterReflectorProvider.cs
│ ├── Internals
│ │ ├── ConstantsUtils.cs
│ │ ├── ReflectorUtils.cs
│ │ └── TypeInfoUtils.cs
│ ├── MemberReflector.CustomAttribute.cs
│ ├── MemberReflector.cs
│ ├── MethodReflector.Call.cs
│ ├── MethodReflector.DisplayName.cs
│ ├── MethodReflector.OpenGeneric.cs
│ ├── MethodReflector.Static.cs
│ ├── MethodReflector.cs
│ ├── MethodSignature.cs
│ ├── Pair.cs
│ ├── ParameterReflector.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── PropertyReflector.Call.cs
│ ├── PropertyReflector.OpenGeneric.cs
│ ├── PropertyReflector.Static.cs
│ ├── PropertyReflector.cs
│ └── TypeReflector.cs
└── AspectCore.Extensions.Windsor
│ ├── AspectCore.Extensions.Windsor.csproj
│ ├── AspectCoreFacility.cs
│ ├── CompatibleCollectionResolver.cs
│ ├── DynamicProxyInterceptor.cs
│ ├── FacilityExtensions.cs
│ ├── InterceptUtils.cs
│ ├── WindsorAspectBuilderFactory.cs
│ └── WindsorServiceResolver.cs
└── tests
├── AspectCore.Extensions.Autofac.Test
├── AdditionalInterceptorSelectorTests.cs
├── AspectCore.Extensions.Autofac.Test.csproj
├── Fakes
│ ├── CacheInterceptorAttribute.cs
│ ├── Controller.cs
│ ├── FakeServiceWithOut.cs
│ ├── IController.cs
│ ├── IService.cs
│ ├── Model.cs
│ └── Service.cs
├── Issues
│ ├── AddDelegateThenUseInterceptorTests.cs
│ ├── PropertiesAutowiredTests.cs
│ └── PropertyInjectorProxyWithVirtualTests.cs
├── NonAspectTest.cs
├── Properties
│ └── AssemblyInfo.cs
├── RegistrationExtensionsTests.cs
└── SpecificationTests.cs
├── AspectCore.Extensions.Configuration.Tests
├── AspectCore.Extensions.Configuration.Tests.csproj
├── ConfigurationBindingTest.cs
└── ConfigurationValueTest.cs
├── AspectCore.Extensions.DependencyInjection.Test
├── AdditionalInterceptorSelectorTests.cs
├── AspectCore.Extensions.DependencyInjection.Test.csproj
├── Issues
│ ├── ConstructorSelectTests.cs
│ ├── InterceptorAttributeWithArrayMemberTests.cs
│ ├── ParamWithInTests.cs
│ └── ValueTupleMorethan7ElementsTests.cs
├── KeyedServiceTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── SpecificationTests.cs
├── UseMicrosoftDISpecificationTests.cs
└── Use_Built_In_ContainerSpecificationTests.cs
├── AspectCore.Extensions.Hosting.Tests
├── AspectCore.Extensions.Hosting.Tests.csproj
├── FakeClasses.cs
└── HostBuilderExtensionsTests.cs
├── AspectCore.Extensions.LightInject.Test
├── AdditionalInterceptorSelectorTests.cs
├── AspectCore.Extensions.LightInject.Test.csproj
├── AsyncIncreamentAttribute.cs
├── AsyncInterceptorTests.cs
├── AwaitBeforeInvokeNextTests.cs
├── DisposeTests.cs
├── ExcuteTimesTests.cs
├── Fakes
│ ├── CacheInterceptorAttribute.cs
│ ├── Controller.cs
│ ├── IController.cs
│ ├── IService.cs
│ ├── Model.cs
│ └── Service.cs
├── NonAspectTest.cs
├── RegistrationExtensionsTests.cs
├── RegistryTests.cs
└── ScopeTests.cs
├── AspectCore.Extensions.Reflection.Test
├── AspectCore.Extensions.Reflection.Test.csproj
├── ConstructorReflectorTest.cs
├── CustomAttributeExtensionsTests.cs
├── CustomAttributeReflectorTests.cs
├── FieldReflectorTests.cs
├── MethodReflectorTests.cs
├── MethodSignatureTest.cs
├── Properties
│ └── AssemblyInfo.cs
├── PropertyReflectorTests.cs
├── TypeReflectorTests.cs
└── VisibleTests.cs
├── AspectCore.Extensions.Windsor.Test
├── AspectCore.Extensions.Windsor.Test.csproj
├── AsyncInterceptorTests.cs
├── AwaitBeforeInvokeNextTests.cs
├── ExcuteTimesTests.cs
├── Fakes
│ ├── CacheInterceptorAttribute.cs
│ ├── CacheService.cs
│ ├── Controller.cs
│ ├── ICacheService.cs
│ ├── IController.cs
│ └── Model.cs
├── RegistrationExtensionsTests.cs
└── ScopedServiceTests.cs
└── AspectCore.Tests
├── AspectCore.Tests.csproj
├── Classes.cs
├── DependencyInjection
└── OptionalArgumentsTests.cs
├── DynamicProxy
├── AdditionalInterceptorSelectorTests.cs
├── AspectInvocationTest.cs
├── AsyncAspectTests.cs
├── ClassProxyTest.cs
├── ConfigureInterceptorSelectorTest.cs
├── DefineAttributesTests.cs
├── DynamicProxyTestBase.cs
├── ExplicitImplementationTest.cs
├── ExplicitMethodTests.cs
├── InheritedTest.cs
├── InterceptorAttributeWithArrayMemberTests.cs
├── InterceptorPropertyInjectionTest.cs
├── NonAspectTest.cs
├── OpenClosedGenericsTests.cs
├── OpenGenericMethodTests.cs
├── OptionalNonNullableMethodParameterTests.cs
├── OptionalNullableMethodParameterTests.cs
├── ParameterInjectionTest.cs
├── PredicatesTests.cs
├── ProxyGeneratorTest.cs
├── RefParameterTests.cs
├── ThrowExceptionDirectlyTests.cs
├── ThrowExceptionTests.cs
└── UnwrapAsyncReturnValueTests.cs
├── Injector
├── AsyncBlockTest.cs
├── ConstructorInjectionTest.cs
├── EnumerableTest.cs
├── GenericTest.cs
├── InjectorTestBase.cs
├── InternalServiceTest.cs
├── ManyEnumerableTest.cs
├── OpenClosedGenericsTests.cs
├── PropertyInjectionTest.cs
├── ScopedTest.cs
├── SingletonTest.cs
├── TransientServiceAccessorTest.cs
└── TransientTest.cs
├── Integrate
├── Container_Built_In_ProxyTests.cs
├── IntegrateTestBase.cs
└── ServiceInterceptorTests.cs
└── Issues
└── DynamicProxy
├── InterfaceDefaultMethodsShouldBeUsedTests.cs
└── NullableEnumWithDefaultValueTests.cs
/.github/workflows/build-pr-ci.yml:
--------------------------------------------------------------------------------
1 | name: Build for PR
2 | on:
3 | pull_request:
4 |
5 | jobs:
6 | build-and-test:
7 | runs-on: windows-latest
8 | steps:
9 | - name: Checkout
10 | uses: actions/checkout@v4
11 | with:
12 | fetch-depth: 0
13 | - name: Setup .NET Core
14 | uses: actions/setup-dotnet@v4
15 | with: # NOTE: we don't need to install 6.x, 8.x and 9.x cause they are included in windows-latest(windows-2022) image.
16 | dotnet-version: 7.x
17 |
18 | - name: Build Reason
19 | run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"
20 |
21 | - name: Build
22 | shell: bash
23 | run: |
24 | for project in $(find ./src -name "*.csproj"); do
25 | dotnet build --configuration Release $project
26 | done
27 |
28 | - name: Run Tests
29 | shell: bash
30 | run: |
31 | for project in $(find ./tests -name "*.csproj"); do
32 | dotnet test --configuration Release $project
33 | done
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 AspectCore Project
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/benchmark/AspectCore.Core.Benchmark/AspectCore.Core.Benchmark.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0;net8.0;net7.0;net6.0
6 | true
7 | true
8 | snupkg
9 | 9.0
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/benchmark/AspectCore.Core.Benchmark/Program.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.Core.Benchmark.Benchmarks;
2 | using BenchmarkDotNet.Running;
3 |
4 | namespace AspectCore.Core.Benchmark
5 | {
6 | public static class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | BenchmarkRunner.Run();
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/AspectCore.Extensions.Reflection.Benchmark.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0;net8.0;net7.0;net6.0
6 | true
7 | true
8 | snupkg
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/Benchmarks/ConstructorReflectorBenchmarks.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using AspectCore.Extensions.Reflection.Benchmark.Fakes;
4 | using BenchmarkDotNet.Attributes;
5 |
6 | namespace AspectCore.Extensions.Reflection.Benchmark.Benchmarks
7 | {
8 | [AllStatisticsColumn]
9 | [MemoryDiagnoser]
10 | public class ConstructorReflectorBenchmarks
11 | {
12 | private readonly ConstructorInfo _constructorInfo;
13 | private readonly ConstructorReflector _reflector;
14 |
15 | private readonly static object[] args = new object[0];
16 |
17 | public ConstructorReflectorBenchmarks()
18 | {
19 | _constructorInfo = typeof(ConstructorFakes).GetTypeInfo().GetConstructor(new Type[0]);
20 | _reflector = _constructorInfo.GetReflector();
21 | }
22 |
23 | [Benchmark]
24 | public void Reflection()
25 | {
26 | _constructorInfo.Invoke(args);
27 | }
28 |
29 | [Benchmark]
30 | public void Reflector()
31 | {
32 | _reflector.Invoke();
33 | }
34 |
35 | [Benchmark]
36 | public void New()
37 | {
38 | var result = new ConstructorFakes();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/Fakes/ConstructorFakes.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
4 | {
5 | public class ConstructorFakes
6 | {
7 | public string Name { get; set; }
8 |
9 | [MethodImpl(MethodImplOptions.NoInlining)]
10 | public ConstructorFakes()
11 | {
12 | //Name = "Nonparametric constructor";
13 | }
14 |
15 | [MethodImpl(MethodImplOptions.NoInlining)]
16 | public ConstructorFakes(string name)
17 | {
18 | Name = "Parametric constructor. param : " + name;
19 | }
20 |
21 | [MethodImpl(MethodImplOptions.NoInlining)]
22 | public ConstructorFakes(ref string name, ref ConstructorFakes fakes)
23 | {
24 | name = Name = "Parametric constructor with ref param.";
25 | fakes = new ConstructorFakes();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/Fakes/FieldFakes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
8 | {
9 | public class FieldFakes
10 | {
11 | public static string StaticFiled;
12 |
13 | public string InstanceField;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/Fakes/MethodFakes.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
4 | {
5 | public class MethodFakes
6 | {
7 | [MethodImpl(MethodImplOptions.NoInlining)]
8 | public object Call() => null;
9 | [MethodImpl(MethodImplOptions.NoInlining)]
10 | public static object StaticCall() => null;
11 | [MethodImpl(MethodImplOptions.NoInlining)]
12 | public virtual object CallVirt() => null;
13 | }
14 | }
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/Fakes/PropertyFakes.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace AspectCore.Extensions.Reflection.Benchmark.Fakes
4 | {
5 | public class PropertyFakes
6 | {
7 | public static string StaticProperty { [MethodImpl(MethodImplOptions.NoInlining)]get; [MethodImpl(MethodImplOptions.NoInlining)]set; }
8 |
9 | public string InstanceProperty { [MethodImpl(MethodImplOptions.NoInlining)]get; [MethodImpl(MethodImplOptions.NoInlining)]set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/benchmark/AspectCore.Extensions.Reflection.Benchmark/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Extensions.Reflection.Benchmark.Benchmarks;
3 | using BenchmarkDotNet.Running;
4 |
5 | namespace AspectCore.Extensions.Reflection.Benchmark
6 | {
7 | static class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | BenchmarkRunner.Run();
12 | BenchmarkRunner.Run();
13 | BenchmarkRunner.Run();
14 | BenchmarkRunner.Run();
15 | BenchmarkRunner.Run();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/build/aspectcore.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dotnetcore/AspectCore-Framework/6a37bcc4207badbd1c183641fe5a04673088338f/build/aspectcore.snk
--------------------------------------------------------------------------------
/build/common.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Lemon
6 | AspectCore Framework
7 | https://avatars1.githubusercontent.com/u/19426425?v=3&s=200
8 | https://github.com/dotnetcore/AspectCore-Framework
9 | https://github.com/dotnetcore/AspectCore-Framework/blob/dev/LICENSE
10 | git
11 | https://github.com/dotnetcore/AspectCore-Framework
12 | false
13 | false
14 | false
15 | False
16 | False
17 |
18 |
--------------------------------------------------------------------------------
/build/sign.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 | $(MSBuildThisFileDirectory)aspectcore.snk
5 | False
6 |
7 |
--------------------------------------------------------------------------------
/build/version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2
4 | 4
5 | 0
6 |
7 | $(VersionMajor).$(VersionMinor).$(VersionPatch)
8 |
9 |
10 |
--------------------------------------------------------------------------------
/docs/reflection.md:
--------------------------------------------------------------------------------
1 | 在从零实现AOP的过程中,难免会需要大量反射相关的操作,虽然在.net 4.5+/.net core中反射的性能有了大幅的优化,但为了追求极致性能,自己实现了部分反射的替代方案,包括构造器调用、方法调用、字段读写,属性读写和特性读取。在重构时,把反射扩展操作封装到单独的项目中,以此方便自己和大家使用。[获取AspectCore.Extension.Reflection](https://github.com/dotnetcore/AspectCore-Framework/blob/master/docs/reflection-extensions.md)
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.AspectScope.Sample/AspectCore.Extensions.AspectScope.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 | true
7 | true
8 | snupkg
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.Autofac.Sample/AspectCore.Extensions.Autofac.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0;net8.0;net7.0;net6.0
6 | true
7 | true
8 | snupkg
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.Autofac.Sample/MethodExecuteLoggerInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading.Tasks;
4 | using AspectCore.DynamicProxy;
5 |
6 | namespace AspectCore.Extensions.Autofac.Sample
7 | {
8 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor
9 | {
10 | public override async Task Invoke(AspectContext context, AspectDelegate next)
11 | {
12 | var stopwatch = Stopwatch.StartNew();
13 | await next(context);
14 | stopwatch.Stop();
15 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms",
16 | context.ImplementationMethod.DeclaringType.Namespace,
17 | context.ImplementationMethod.DeclaringType.Name,
18 | context.ImplementationMethod.Name,
19 | context.ImplementationMethod.DeclaringType.Assembly.GetName().Name,
20 | stopwatch.ElapsedMilliseconds
21 | );
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.DataAnnotations.Sample/AspectCore.Extensions.DataAnnotations.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 | DataAnnotations.Sample
7 | true
8 | true
9 | snupkg
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.DataAnnotations.Sample/IAccountService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using AspectCore.Extensions.DataValidation;
5 |
6 | namespace DataAnnotations.Sample
7 | {
8 | public interface IAccountService
9 | {
10 | void Register(RegisterInput input);
11 | string TestString(string a);
12 | }
13 |
14 | public class AccountService : IAccountService
15 | {
16 | public IDataState DataState { get; set; }
17 | public string TestString(string str)
18 | {
19 | return str;
20 | }
21 | public void Register(RegisterInput input)
22 | {
23 | if (DataState.IsValid)
24 | {
25 | //验证通过
26 | Console.WriteLine("register.. name:{0},email:{1}", input.Name, input.Email);
27 | }
28 |
29 | if (!DataState.IsValid)
30 | {
31 | //验证失败
32 | foreach(var error in DataState.Errors)
33 | {
34 | Console.WriteLine("error.. key:{0},message:{1}", error.Key, error.ErrorMessage);
35 | }
36 | }
37 | Console.WriteLine();
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.DataAnnotations.Sample/RegisterInput.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace DataAnnotations.Sample
5 | {
6 | public class RegisterInput
7 | {
8 | [Required]
9 | public string Name { get; set; }
10 |
11 | [Required]
12 | [EmailAddress]
13 | public string Email { get; set; }
14 |
15 | [Required]
16 | [StringLength(18, MinimumLength = 6)]
17 | public string Password { get; set; }
18 | }
19 | }
--------------------------------------------------------------------------------
/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/AspectCore.Extensions.DependencyInjection.ConsoleSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | net9.0;net8.0;net7.0;net6.0
5 | true
6 | true
7 | snupkg
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/Configuration/AspectPredicate.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace AspectCore.Configuration
4 | {
5 | public delegate bool AspectPredicate(MethodInfo method);
6 | }
7 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/Configuration/IAspectConfiguration.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.DynamicProxy;
2 | using AspectCore.DependencyInjection;
3 |
4 | namespace AspectCore.Configuration
5 | {
6 | [NonAspect]
7 | public interface IAspectConfiguration
8 | {
9 | AspectValidationHandlerCollection ValidationHandlers { get; }
10 |
11 | InterceptorCollection Interceptors { get; }
12 |
13 | NonAspectPredicateCollection NonAspectPredicates { get; }
14 |
15 | bool ThrowAspectException { get; set; }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/Configuration/InterceptorCollection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace AspectCore.Configuration
6 | {
7 | public sealed class InterceptorCollection : IEnumerable
8 | {
9 | private readonly ICollection _collection = new List();
10 |
11 | public InterceptorCollection Add(InterceptorFactory interceptorFactory)
12 | {
13 | if (interceptorFactory == null)
14 | {
15 | throw new ArgumentNullException(nameof(interceptorFactory));
16 | }
17 | _collection.Add(interceptorFactory);
18 | return this;
19 | }
20 |
21 | public int Count => _collection.Count;
22 |
23 | public IEnumerator GetEnumerator()
24 | {
25 | return _collection.GetEnumerator();
26 | }
27 |
28 | IEnumerator IEnumerable.GetEnumerator()
29 | {
30 | return GetEnumerator();
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/Configuration/InterceptorFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using AspectCore.DynamicProxy;
4 |
5 | namespace AspectCore.Configuration
6 | {
7 | public abstract class InterceptorFactory
8 | {
9 | private static readonly AspectPredicate[] EmptyPredicates = new AspectPredicate[0];
10 | private readonly AspectPredicate[] _predicates;
11 |
12 | public AspectPredicate[] Predicates
13 | {
14 | get
15 | {
16 | return _predicates;
17 | }
18 | }
19 |
20 | public InterceptorFactory(params AspectPredicate[] predicates)
21 | {
22 | _predicates = predicates ?? EmptyPredicates;
23 | }
24 |
25 | public bool CanCreated(MethodInfo method)
26 | {
27 | if (_predicates.Length == 0)
28 | {
29 | return true;
30 | }
31 | foreach (var predicate in _predicates)
32 | {
33 | if (predicate(method)) return true;
34 | }
35 | return false;
36 | }
37 |
38 | public abstract IInterceptor CreateInstance(IServiceProvider serviceProvider);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/Configuration/NonAspectPredicateCollection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace AspectCore.Configuration
6 | {
7 | public sealed class NonAspectPredicateCollection : IEnumerable
8 | {
9 | private readonly ICollection _collection = new List();
10 |
11 | public NonAspectPredicateCollection Add(AspectPredicate interceptorFactory)
12 | {
13 | _collection.Add(interceptorFactory);
14 | return this;
15 | }
16 |
17 | public int Count => _collection.Count;
18 |
19 | public IEnumerator GetEnumerator()
20 | {
21 | return _collection.GetEnumerator();
22 | }
23 |
24 | IEnumerator IEnumerable.GetEnumerator()
25 | {
26 | return GetEnumerator();
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/ConfigurationExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.Configuration;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | public static class ConfigurationExtensions
7 | {
8 | public static IServiceContext Configure(this IServiceContext serviceContext, Action configure)
9 | {
10 | if (serviceContext == null)
11 | {
12 | throw new ArgumentNullException(nameof(serviceContext));
13 | }
14 | configure?.Invoke(serviceContext.Configuration);
15 | return serviceContext;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/Definitions/DelegateServiceDefinition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.DependencyInjection
4 | {
5 | public class DelegateServiceDefinition : ServiceDefinition
6 | {
7 | public DelegateServiceDefinition(Type serviceType, Func implementationDelegate, Lifetime lifetime) : base(serviceType, lifetime)
8 | {
9 | ImplementationDelegate = implementationDelegate ?? throw new ArgumentNullException(nameof(implementationDelegate));
10 | }
11 |
12 | public Func ImplementationDelegate { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/Definitions/InstanceServiceDefinition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | public sealed class InstanceServiceDefinition : ServiceDefinition
7 | {
8 | public InstanceServiceDefinition(Type serviceType, object implementationInstance) : base(serviceType, Lifetime.Singleton)
9 | {
10 | ImplementationInstance = implementationInstance ?? throw new ArgumentNullException(nameof(implementationInstance));
11 | }
12 |
13 | public object ImplementationInstance { get; }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/Definitions/ServiceDefinition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.DynamicProxy;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | [NonAspect]
7 | public abstract class ServiceDefinition
8 | {
9 | public Type ServiceType { get; }
10 |
11 | public Lifetime Lifetime { get; }
12 |
13 | public ServiceDefinition(Type serviceType, Lifetime lifetime)
14 | {
15 | Lifetime = lifetime;
16 | ServiceType = serviceType ?? throw new ArgumentNullException(nameof(serviceType));
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/Definitions/TypeServiceDefinition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | public sealed class TypeServiceDefinition : ServiceDefinition
7 | {
8 | public TypeServiceDefinition(Type serviceType, Type implementationType, Lifetime lifetime) : base(serviceType, lifetime)
9 | {
10 | ImplementationType = implementationType ?? throw new ArgumentNullException(nameof(implementationType));
11 | }
12 |
13 | public Type ImplementationType { get; }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/FromServiceContextAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.DependencyInjection
4 | {
5 | [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)]
6 | public class FromServiceContextAttribute : Attribute
7 | {
8 | public FromServiceContextAttribute()
9 | {
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/ILifetimeServiceContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using AspectCore.DynamicProxy;
4 |
5 | namespace AspectCore.DependencyInjection
6 | {
7 | [NonAspect]
8 | public interface ILifetimeServiceContext : IEnumerable
9 | {
10 | Lifetime Lifetime { get; }
11 |
12 | int Count { get; }
13 |
14 | void Add(ServiceDefinition item);
15 |
16 | bool Contains(Type serviceType);
17 | }
18 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IManyEnumerable.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 | using AspectCore.DynamicProxy;
4 |
5 | namespace AspectCore.DependencyInjection
6 | {
7 | [NonAspect, NonCallback]
8 | public interface IManyEnumerable : IEnumerable, IEnumerable
9 | {
10 | }
11 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IPropertyInjector.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.DynamicProxy;
2 |
3 | namespace AspectCore.DependencyInjection
4 | {
5 | [NonAspect]
6 | public interface IPropertyInjector
7 | {
8 | void Invoke(object implementation);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IPropertyInjectorFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.DynamicProxy;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | [NonAspect]
7 | public interface IPropertyInjectorFactory
8 | {
9 | IPropertyInjector Create(Type implementationType);
10 | }
11 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IScopeResolverFactory.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.DynamicProxy;
2 |
3 | namespace AspectCore.DependencyInjection
4 | {
5 | [NonAspect]
6 | public interface IScopeResolverFactory
7 | {
8 | IServiceResolver CreateScope();
9 | }
10 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IServiceContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using AspectCore.Configuration;
4 | using AspectCore.DynamicProxy;
5 |
6 | namespace AspectCore.DependencyInjection
7 | {
8 | [NonAspect]
9 | public interface IServiceContext : IEnumerable
10 | {
11 | ILifetimeServiceContext Singletons { get; }
12 |
13 | ILifetimeServiceContext Scopeds { get; }
14 |
15 | ILifetimeServiceContext Transients { get; }
16 |
17 | IAspectConfiguration Configuration { get; }
18 |
19 | int Count { get; }
20 |
21 | void Add(ServiceDefinition item);
22 |
23 | bool Remove(ServiceDefinition item);
24 |
25 | bool Contains(Type serviceType);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IServiceResolveCallback.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.DynamicProxy;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | [NonAspect, NonCallback]
7 | public interface IServiceResolveCallback
8 | {
9 | object Invoke(IServiceResolver resolver, object instance, ServiceDefinition service);
10 | }
11 |
12 | public sealed class NonCallback : Attribute
13 | {
14 | }
15 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/IServiceResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AspectCore.DynamicProxy;
3 |
4 | namespace AspectCore.DependencyInjection
5 | {
6 | [NonAspect]
7 | public interface IServiceResolver : IServiceProvider, IDisposable
8 | #if NET8_0_OR_GREATER
9 | , Microsoft.Extensions.DependencyInjection.IKeyedServiceProvider
10 | #endif
11 | {
12 | object Resolve(Type serviceType);
13 | }
14 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/ITransientServiceAccessor.cs:
--------------------------------------------------------------------------------
1 | using AspectCore.DynamicProxy;
2 |
3 | namespace AspectCore.DependencyInjection
4 | {
5 | [NonAspect]
6 | public interface ITransientServiceAccessor where T : class
7 | {
8 | T Value { get; }
9 | }
10 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DependencyInjection/Lifetime.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.DependencyInjection
2 | {
3 | public enum Lifetime
4 | {
5 | ///
6 | /// Specifies that a single instance of the service will be created.
7 | ///
8 | Singleton,
9 | ///
10 | /// Specifies that a new instance of the service will be created for each scope.
11 | ///
12 | ///
13 | /// In ASP.NET Core applications a scope is created around each server request.
14 | ///
15 | Scoped,
16 | ///
17 | /// Specifies that a new instance of the service will be created every time it is requested.
18 | ///
19 | Transient
20 | }
21 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AbstractInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | [NonAspect]
6 | public abstract class AbstractInterceptor : IInterceptor
7 | {
8 | public virtual bool AllowMultiple { get; } = false;
9 |
10 | public virtual int Order { get; set; } = 0;
11 |
12 | public bool Inherited { get; set; } = false;
13 |
14 | public abstract Task Invoke(AspectContext context, AspectDelegate next);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AbstractInterceptorAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace AspectCore.DynamicProxy
5 | {
6 | ///
7 | /// Standard interceptor definition via custom attribute.
8 | ///
9 | [NonAspect]
10 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
11 | public abstract class AbstractInterceptorAttribute : Attribute, IInterceptor
12 | {
13 | public virtual bool AllowMultiple { get; } = false;
14 |
15 | public virtual int Order { get; set; } = 0;
16 |
17 | public bool Inherited { get; set; } = false;
18 |
19 | public abstract Task Invoke(AspectContext context, AspectDelegate next);
20 | }
21 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectActivatorContext.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | public struct AspectActivatorContext
6 | {
7 | public MethodInfo ServiceMethod { get; }
8 |
9 | public MethodInfo TargetMethod { get; }
10 |
11 | public MethodInfo ProxyMethod { get; }
12 |
13 | public object TargetInstance { get; }
14 |
15 | public object ProxyInstance { get; }
16 |
17 | public object[] Parameters { get; }
18 |
19 | public AspectActivatorContext(MethodInfo serviceMethod, MethodInfo targetMethod, MethodInfo proxyMethod,
20 | object targetInstance, object proxyInstance, object[] parameters)
21 | {
22 | ServiceMethod = serviceMethod;
23 | TargetMethod = targetMethod;
24 | ProxyMethod = proxyMethod;
25 | TargetInstance = targetInstance;
26 | ProxyInstance = proxyInstance;
27 | Parameters = parameters;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using System.Threading.Tasks;
5 |
6 | namespace AspectCore.DynamicProxy
7 | {
8 | [NonAspect]
9 | public abstract class AspectContext
10 | {
11 | public abstract IDictionary AdditionalData { get; }
12 |
13 | public abstract object ReturnValue { get; set; }
14 |
15 | public abstract IServiceProvider ServiceProvider { get; }
16 |
17 | public abstract MethodInfo ServiceMethod { get; }
18 |
19 | public abstract object Implementation { get; }
20 |
21 | public abstract MethodInfo ImplementationMethod { get; }
22 |
23 | public abstract object[] Parameters { get; }
24 |
25 | public abstract MethodInfo ProxyMethod { get; }
26 |
27 | public abstract object Proxy { get; }
28 |
29 | public abstract Task Break();
30 |
31 | public abstract Task Invoke(AspectDelegate next);
32 |
33 | public abstract Task Complete();
34 | }
35 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectDelegate.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | public delegate Task AspectDelegate(AspectContext context);
6 | }
7 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidCastException.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.DynamicProxy
2 | {
3 | public class AspectInvalidCastException : AspectInvocationException
4 | {
5 | public AspectInvalidCastException(AspectContext aspectContext, string message) : base(aspectContext, message) { }
6 | }
7 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectInvalidOperationException.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.DynamicProxy
2 | {
3 | public class AspectInvalidOperationException : AspectInvocationException
4 | {
5 | public AspectInvalidOperationException(AspectContext aspectContext, string message) : base(aspectContext, message) { }
6 | }
7 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectInvocationException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | public class AspectInvocationException : Exception
6 | {
7 | public AspectContext AspectContext { get; }
8 |
9 | public AspectInvocationException(AspectContext aspectContext, string message) : this(aspectContext, message, null) { }
10 |
11 | public AspectInvocationException(AspectContext aspectContext, Exception innerException)
12 | : this(aspectContext, $"Exception has been thrown by the aspect of an invocation. ---> {innerException?.Message}.", innerException) { }
13 |
14 | public AspectInvocationException(AspectContext aspectContext, string message, Exception innerException) : base(message, innerException)
15 | {
16 | AspectContext = aspectContext;
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectValidationContext.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System;
3 |
4 | namespace AspectCore.DynamicProxy
5 | {
6 | public struct AspectValidationContext : IEquatable
7 | {
8 | public MethodInfo Method { get; set; }
9 |
10 | public bool StrictValidation { get; set; }
11 |
12 | public bool Equals(AspectValidationContext other)
13 | {
14 | return Method == other.Method && StrictValidation == other.StrictValidation;
15 | }
16 |
17 | public override bool Equals(object obj)
18 | {
19 | if (obj == null)
20 | {
21 | return false;
22 | }
23 | if (obj is AspectActivatorContext other)
24 | return Equals(other);
25 | return false;
26 | }
27 |
28 | public override int GetHashCode()
29 | {
30 | var hash_1 = this.Method?.GetHashCode() ?? 0;
31 | var hash_2 = StrictValidation.GetHashCode();
32 | return (hash_1 << 5) + hash_1 ^ hash_2;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AspectValidationDelegate.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | public delegate bool AspectValidationDelegate(AspectValidationContext context);
6 | }
7 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/AsyncAspectAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
6 | public class AsyncAspectAttribute : Attribute
7 | {
8 | }
9 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/DelegateInterceptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace AspectCore.DynamicProxy
5 | {
6 | [NonAspect]
7 | public class DelegateInterceptor : IInterceptor
8 | {
9 | private readonly Func _aspectDelegate;
10 |
11 | public bool AllowMultiple => true;
12 |
13 | public bool Inherited { get; set; } = false;
14 |
15 | public int Order { get; set; }
16 |
17 | public DelegateInterceptor(Func aspectDelegate, int order = 0)
18 | {
19 | _aspectDelegate = aspectDelegate ?? throw new ArgumentNullException(nameof(aspectDelegate));
20 | Order = order;
21 | }
22 |
23 | public Task Invoke(AspectContext context, AspectDelegate next)
24 | {
25 | return _aspectDelegate(next)(context);
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/DynamicallyAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
6 | public sealed class DynamicallyAttribute : Attribute
7 | {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/IAdditionalInterceptorSelector.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using System.Text;
5 |
6 | namespace AspectCore.DynamicProxy
7 | {
8 | [NonAspect]
9 | public interface IAdditionalInterceptorSelector
10 | {
11 | IEnumerable Select(MethodInfo serviceMethod, MethodInfo implementationMethod);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/IAspectActivator.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | [NonAspect]
6 | public interface IAspectActivator
7 | {
8 | TResult Invoke(AspectActivatorContext activatorContext);
9 |
10 | Task InvokeTask(AspectActivatorContext activatorContext);
11 |
12 | ValueTask InvokeValueTask(AspectActivatorContext activatorContext);
13 | }
14 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/IAspectActivatorFactory.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.DynamicProxy
2 | {
3 | [NonAspect]
4 | public interface IAspectActivatorFactory
5 | {
6 | IAspectActivator Create();
7 | }
8 | }
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/IAspectBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace AspectCore.DynamicProxy
5 | {
6 | [NonAspect]
7 | public interface IAspectBuilder
8 | {
9 | IEnumerable> Delegates { get; }
10 |
11 | AspectDelegate Build();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/IAspectBuilderFactory.cs:
--------------------------------------------------------------------------------
1 | namespace AspectCore.DynamicProxy
2 | {
3 | [NonAspect]
4 | public interface IAspectBuilderFactory
5 | {
6 | IAspectBuilder Create(AspectContext context);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/AspectCore.Abstractions/DynamicProxy/IAspectCaching.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace AspectCore.DynamicProxy
4 | {
5 | [NonAspect]
6 | public interface IAspectCaching : IDisposable
7 | {
8 | string Name { get; }
9 |
10 | object Get(object key);
11 |
12 | void Set(object key, object value);
13 |
14 | object GetOrAdd(object key, Func