├── .gitattributes ├── .gitignore ├── LICENSE ├── NuGet.config ├── README.md ├── appveyor.yml ├── aspectscope ├── AspectCore.AspectScope.sln ├── sample │ └── AspectCore.Extensions.AspectScope.Sample │ │ ├── AspectCore.Extensions.AspectScope.Sample.csproj │ │ └── Program.cs └── src │ └── 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 ├── build.cake ├── build.ps1 ├── build ├── aspectcore.snk ├── common.props ├── index.cake ├── net45.props ├── net46.props ├── netstandard16.props ├── netstandard20.props ├── sign.props ├── util.cake ├── version.cake └── version.props ├── core ├── AspectCore.Core.sln ├── README.md ├── performance │ ├── AspectCore.Benchmark │ │ ├── AspectCore.Benchmark.csproj │ │ └── Program.cs │ └── AspectCore.IoC.Benchmarks │ │ ├── AspectCore.IoC.Benchmarks.csproj │ │ ├── Program.cs │ │ └── SimpleObjectBenchmarks.cs ├── src │ ├── AspectCore.Abstractions │ │ ├── AspectCore.Abstractions.csproj │ │ ├── Configuration │ │ │ ├── AspectPredicate.cs │ │ │ ├── AspectValidationHandlerCollection.cs │ │ │ ├── IAspectConfiguration.cs │ │ │ ├── InterceptorCollection.cs │ │ │ ├── InterceptorFactory.cs │ │ │ └── NonAspectPredicateCollection.cs │ │ ├── DynamicProxy │ │ │ ├── AbstractInterceptor.cs │ │ │ ├── AbstractInterceptorAttribute.cs │ │ │ ├── AspectActivatorContext.cs │ │ │ ├── AspectContext.cs │ │ │ ├── AspectDelegate.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 │ │ ├── Injector │ │ │ ├── ConfigurationExtensions.cs │ │ │ ├── Definitions │ │ │ │ ├── DelegateServiceDefinition.cs │ │ │ │ ├── InstanceServiceDefinition.cs │ │ │ │ ├── ServiceDefinition.cs │ │ │ │ └── TypeServiceDefinition.cs │ │ │ ├── FromContainerAttribute.cs │ │ │ ├── ILifetimeServiceContainer.cs │ │ │ ├── IManyEnumerable.cs │ │ │ ├── IPropertyInjector.cs │ │ │ ├── IPropertyInjectorFactory.cs │ │ │ ├── IScopeResolverFactory.cs │ │ │ ├── IServiceContainer.cs │ │ │ ├── IServiceResolver.cs │ │ │ ├── ITransientServiceAccessor.cs │ │ │ ├── Lifetime.cs │ │ │ ├── LifetimeServiceContainerExtensions.cs │ │ │ ├── ServiceContainerExtensions.cs │ │ │ ├── ServiceProviderExtensions.cs │ │ │ └── ServiceResolverExtensions.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 │ │ ├── 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 │ │ ├── Injector │ │ ├── ConstructorCallSiteResolver.cs │ │ ├── EnumerableServiceDefintion.cs │ │ ├── Extensions │ │ │ ├── LinkedListExtensions.cs │ │ │ ├── ServiceContainerBuildExtensions.cs │ │ │ └── ServiceDefinitionExtensions.cs │ │ ├── LifetimeServiceContainer.cs │ │ ├── ManyEnumerable.cs │ │ ├── PropertyInjector.cs │ │ ├── PropertyInjectorFactory.cs │ │ ├── PropertyResolver.cs │ │ ├── PropertyResolverSelector.cs │ │ ├── ProxyServiceDefinition.cs │ │ ├── ScopeResolverFactory.cs │ │ ├── ServiceCallSiteResolver.cs │ │ ├── ServiceContainer.cs │ │ ├── ServiceResolver.cs │ │ ├── ServiceTable.cs │ │ ├── ServiceValidator.cs │ │ └── TransientServiceAccessor.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ └── Utils │ │ ├── ActivatorUtils.cs │ │ ├── ArrayUtils.cs │ │ ├── MethodUtils.cs │ │ ├── PropertyInjectionUtils.cs │ │ ├── ProxyGeneratorUtils.cs │ │ ├── ReflectionUtils.cs │ │ └── TaskUtils.cs └── test │ ├── AspectCore.Abstractions.Test │ ├── AspectActivatorTest.cs │ ├── AspectConfigurationTest.cs │ ├── AspectContextTest.cs │ ├── AspectCore.Abstractions.Test.xproj │ ├── AspectValidatorTest.cs │ ├── CanInheritedTest.cs │ ├── ConfigurationOptionTest.cs │ ├── DynamicallyTests.cs │ ├── Fakes │ │ ├── AspectValidatorFactory.cs │ │ ├── DescriptorWithParameter.cs │ │ ├── ITargetService.cs │ │ ├── IValidatorModel.cs │ │ ├── IncrementAttribute.cs │ │ ├── InjectedInterceptor.cs │ │ ├── InstanceServiceProvider.cs │ │ ├── InstanceSupportOriginalService.cs │ │ ├── InterceptorMatcherModel.cs │ │ ├── ItemInterceptorAttribute.cs │ │ ├── MatcherTestAttribute.cs │ │ ├── OriginalServiceProvider.cs │ │ ├── ProxyService.cs │ │ ├── TargetService.cs │ │ └── ValidatorModel.cs │ ├── InterceptorInjectorTest.cs │ ├── InterceptorMatcherTest.cs │ ├── MatchTest.cs │ ├── MethodAccessorTest.cs │ ├── ParameterCollectionTest.cs │ ├── ParameterDescriptorTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── PropertyAccessorTest.cs │ ├── ProxyDescriptorTest.cs │ ├── ProxyGeneratorTest.cs │ ├── ReturnParameterDescriptorTest.cs │ ├── ServiceInstanceAccessorTests.cs │ ├── ServiceProviderAccessorTests.cs │ ├── TargetDescriptorTest.cs │ └── project.json │ └── AspectCore.Tests │ ├── AspectCore.Tests.csproj │ ├── Classes.cs │ ├── DynamicProxy │ ├── AdditionalInterceptorSelectorTests.cs │ ├── AspectInvocationTest.cs │ ├── AsyncAspectTests.cs │ ├── ClassProxyTest.cs │ ├── ConfigureInterceptorSelectorTest.cs │ ├── DynamicProxyTestBase.cs │ ├── ExplicitImplementationTest.cs │ ├── ExplicitMethodTests.cs │ ├── InheritedTest.cs │ ├── InterceptorPropertyInjectionTest.cs │ ├── NonAspectTest.cs │ ├── OpenClosedGenericsTests.cs │ ├── OpenGenericMethodTests.cs │ ├── ParameterInjectionTest.cs │ ├── ProxyGeneratorTest.cs │ └── RefParameterTests.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 ├── datavalidation ├── AspectCore.Extensions.DataValidation.sln ├── sample │ └── AspectCore.Extensions.DataAnnotations.Sample │ │ ├── AspectCore.Extensions.DataAnnotations.Sample.csproj │ │ ├── IAccountService.cs │ │ ├── Program.cs │ │ └── RegisterInput.cs └── src │ ├── 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 ├── docs ├── 0.AOP简单介绍.md ├── 1.使用指南.md ├── injector.md └── reflection-extensions.md ├── extras ├── AspectCore.Extras.sln ├── sample │ ├── AspectCore.Extensions.AspNetCore.Sample │ │ ├── .bowerrc │ │ ├── AspectCore.Extensions.AspNetCore.Sample.csproj │ │ ├── Controllers │ │ │ ├── AccountController.cs │ │ │ ├── BookController.cs │ │ │ ├── HomeController.cs │ │ │ └── ManageController.cs │ │ ├── Data │ │ │ ├── ApplicationDbContext.cs │ │ │ └── Migrations │ │ │ │ ├── 00000000000000_CreateIdentitySchema.Designer.cs │ │ │ │ ├── 00000000000000_CreateIdentitySchema.cs │ │ │ │ └── ApplicationDbContextModelSnapshot.cs │ │ ├── Extensions │ │ │ ├── EmailSenderExtensions.cs │ │ │ └── UrlHelperExtensions.cs │ │ ├── Models │ │ │ ├── AccountViewModels │ │ │ │ ├── ExternalLoginViewModel.cs │ │ │ │ ├── ForgotPasswordViewModel.cs │ │ │ │ ├── LoginViewModel.cs │ │ │ │ ├── LoginWith2faViewModel.cs │ │ │ │ ├── LoginWithRecoveryCodeViewModel.cs │ │ │ │ ├── RegisterViewModel.cs │ │ │ │ └── ResetPasswordViewModel.cs │ │ │ ├── ApplicationUser.cs │ │ │ ├── CreateBookViewModel.cs │ │ │ ├── ErrorViewModel.cs │ │ │ └── ManageViewModels │ │ │ │ ├── ChangePasswordViewModel.cs │ │ │ │ ├── EnableAuthenticatorViewModel.cs │ │ │ │ ├── ExternalLoginsViewModel.cs │ │ │ │ ├── GenerateRecoveryCodesViewModel.cs │ │ │ │ ├── IndexViewModel.cs │ │ │ │ ├── RemoveLoginViewModel.cs │ │ │ │ ├── SetPasswordViewModel.cs │ │ │ │ └── TwoFactorAuthenticationViewModel.cs │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Services │ │ │ ├── BookService.cs │ │ │ ├── EmailSender.cs │ │ │ ├── IBookService.cs │ │ │ └── IEmailSender.cs │ │ ├── Startup.cs │ │ ├── Views │ │ │ ├── Account │ │ │ │ ├── AccessDenied.cshtml │ │ │ │ ├── ConfirmEmail.cshtml │ │ │ │ ├── ExternalLogin.cshtml │ │ │ │ ├── ForgotPassword.cshtml │ │ │ │ ├── ForgotPasswordConfirmation.cshtml │ │ │ │ ├── Lockout.cshtml │ │ │ │ ├── Login.cshtml │ │ │ │ ├── LoginWith2fa.cshtml │ │ │ │ ├── LoginWithRecoveryCode.cshtml │ │ │ │ ├── Register.cshtml │ │ │ │ ├── ResetPassword.cshtml │ │ │ │ ├── ResetPasswordConfirmation.cshtml │ │ │ │ └── SignedOut.cshtml │ │ │ ├── Book │ │ │ │ └── Create.cshtml │ │ │ ├── Home │ │ │ │ ├── About.cshtml │ │ │ │ ├── Contact.cshtml │ │ │ │ └── Index.cshtml │ │ │ ├── Manage │ │ │ │ ├── ChangePassword.cshtml │ │ │ │ ├── Disable2fa.cshtml │ │ │ │ ├── EnableAuthenticator.cshtml │ │ │ │ ├── ExternalLogins.cshtml │ │ │ │ ├── GenerateRecoveryCodes.cshtml │ │ │ │ ├── Index.cshtml │ │ │ │ ├── ManageNavPages.cs │ │ │ │ ├── ResetAuthenticator.cshtml │ │ │ │ ├── SetPassword.cshtml │ │ │ │ ├── TwoFactorAuthentication.cshtml │ │ │ │ ├── _Layout.cshtml │ │ │ │ ├── _ManageNav.cshtml │ │ │ │ ├── _StatusMessage.cshtml │ │ │ │ └── _ViewImports.cshtml │ │ │ ├── Shared │ │ │ │ ├── Error.cshtml │ │ │ │ ├── _Layout.cshtml │ │ │ │ ├── _LoginPartial.cshtml │ │ │ │ └── _ValidationScriptsPartial.cshtml │ │ │ ├── _ViewImports.cshtml │ │ │ └── _ViewStart.cshtml │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ ├── bower.json │ │ ├── bundleconfig.json │ │ └── wwwroot │ │ │ ├── css │ │ │ ├── site.css │ │ │ └── site.min.css │ │ │ ├── favicon.ico │ │ │ ├── images │ │ │ ├── banner1.svg │ │ │ ├── banner2.svg │ │ │ ├── banner3.svg │ │ │ └── banner4.svg │ │ │ ├── js │ │ │ ├── site.js │ │ │ └── site.min.js │ │ │ └── lib │ │ │ ├── bootstrap │ │ │ ├── .bower.json │ │ │ ├── LICENSE │ │ │ └── dist │ │ │ │ ├── css │ │ │ │ ├── bootstrap-theme.css │ │ │ │ ├── bootstrap-theme.css.map │ │ │ │ ├── bootstrap-theme.min.css │ │ │ │ ├── bootstrap-theme.min.css.map │ │ │ │ ├── bootstrap.css │ │ │ │ ├── bootstrap.css.map │ │ │ │ ├── bootstrap.min.css │ │ │ │ └── bootstrap.min.css.map │ │ │ │ ├── fonts │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ │ └── js │ │ │ │ ├── bootstrap.js │ │ │ │ ├── bootstrap.min.js │ │ │ │ └── npm.js │ │ │ ├── jquery-validation-unobtrusive │ │ │ ├── .bower.json │ │ │ ├── jquery.validate.unobtrusive.js │ │ │ └── jquery.validate.unobtrusive.min.js │ │ │ ├── jquery-validation │ │ │ ├── .bower.json │ │ │ ├── LICENSE.md │ │ │ └── dist │ │ │ │ ├── additional-methods.js │ │ │ │ ├── additional-methods.min.js │ │ │ │ ├── jquery.validate.js │ │ │ │ └── jquery.validate.min.js │ │ │ └── jquery │ │ │ ├── .bower.json │ │ │ ├── LICENSE.txt │ │ │ └── dist │ │ │ ├── jquery.js │ │ │ ├── jquery.min.js │ │ │ └── jquery.min.map │ ├── AspectCore.Extensions.Autofac.Sample │ │ ├── AspectCore.Extensions.Autofac.Sample.csproj │ │ ├── MethodExecuteLoggerInterceptor.cs │ │ └── Program.cs │ ├── AspectCore.Extensions.Autofac.WebSample │ │ ├── AspectCore.Extensions.Autofac.WebSample.csproj │ │ ├── Controllers │ │ │ └── ValuesController.cs │ │ ├── DynamicProxy │ │ │ └── MethodExecuteLoggerInterceptor.cs │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Services │ │ │ └── IValuesService.cs │ │ ├── Startup.cs │ │ ├── appsettings.Development.json │ │ └── appsettings.json │ ├── AspectCore.Extensions.DependencyInjection.ConsoleSample │ │ ├── AspectCore.Extensions.DependencyInjection.ConsoleSample.csproj │ │ └── Program.cs │ └── AspectCore.Extensions.DependencyInjection.Sample │ │ ├── AspectCore.Extensions.DependencyInjection.Sample.csproj │ │ ├── Controllers │ │ ├── ControllerBase.cs │ │ └── ValuesController.cs │ │ ├── DynamicProxy │ │ └── MethodExecuteLoggerInterceptor.cs │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Services │ │ └── IValuesService.cs │ │ ├── Startup.cs │ │ ├── appsettings.Development.json │ │ └── appsettings.json ├── src │ ├── 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.Autofac │ │ ├── AspectCore.Extensions.Autofac.csproj │ │ ├── AutofacScopeResolverFactory.cs │ │ ├── AutofacServiceResolver.cs │ │ ├── ContainerBuilderExtensions.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── RegistrationExtensions.cs │ ├── AspectCore.Extensions.DependencyInjection │ │ ├── AspectCore.Extensions.DependencyInjection.csproj │ │ ├── AspectCoreServiceProviderFactory.cs │ │ ├── DynamicProxyServiceProviderFactory.cs │ │ ├── MsdiScopeResolverFactory.cs │ │ ├── MsdiServiceResolver.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── ServiceCollectionAddExtensions.cs │ │ ├── ServiceCollectionBuildExtensions.cs │ │ ├── ServiceCollectionExtensions.cs │ │ ├── ServiceCollectionToContainerExtensions.cs │ │ ├── ServiceScope.cs │ │ ├── ServiceScopeFactory.cs │ │ ├── ServiceValidator.cs │ │ └── SupportRequiredService.cs │ ├── AspectCore.Extensions.Hosting │ │ ├── AspectCore.Extensions.Hosting.csproj │ │ └── HostBuilderExtensions.cs │ └── AspectCore.Extensions.Windsor │ │ ├── AspectCore.Extensions.Windsor.csproj │ │ ├── AspectCoreFacility.cs │ │ ├── AspectCoreInterceptor.cs │ │ ├── CompatibleCollectionResolver.cs │ │ ├── FacilityExtensions.cs │ │ ├── InterceptUtils.cs │ │ ├── WindsorAspectBuilderFactory.cs │ │ └── WindsorServiceResolver.cs └── test │ ├── AspectCore.Extensions.Autofac.Test │ ├── AdditionalInterceptorSelectorTests.cs │ ├── AspectCore.Extensions.Autofac.Test.csproj │ ├── Fakes │ │ ├── CacheInterceptorAttribute.cs │ │ ├── Controller.cs │ │ ├── IController.cs │ │ ├── IService.cs │ │ ├── Model.cs │ │ └── Service.cs │ ├── NonAspectTest.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RegistrationExtensionsTests.cs │ └── SpecificationTests.cs │ ├── AspectCore.Extensions.DependencyInjection.Test │ ├── AdditionalInterceptorSelectorTests.cs │ ├── AspectCore.Extensions.DependencyInjection.Test.csproj │ ├── 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.Windsor.Test │ ├── AspectCore.Extensions.Windsor.Test.csproj │ ├── AsyncInterceptorTests.cs │ ├── Fakes │ ├── CacheInterceptorAttribute.cs │ ├── CacheService.cs │ ├── Controller.cs │ ├── ICacheService.cs │ ├── IController.cs │ └── Model.cs │ ├── RegistrationExtensionsTests.cs │ └── ScopedServiceTests.cs └── reflection ├── AspectCore.Reflection.sln ├── README.md ├── performance └── 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 ├── src └── 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 │ ├── 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.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 └── test └── 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 /NuGet.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | os: Visual Studio 2017 3 | branches: 4 | only: 5 | - master 6 | environment: 7 | BUILDING_ON_PLATFORM: win 8 | BuildEnvironment: appveyor 9 | skip_commits: 10 | files: 11 | - LICENSE 12 | build_script: 13 | - ps: ./build.ps1 14 | test: off 15 | artifacts: 16 | - path: artifacts/packages/*.nupkg 17 | deploy: 18 | - provider: NuGet 19 | server: https://www.myget.org/F/aspectcore/api/v2/package 20 | api_key: 21 | secure: jpjXYvzq6XOX2E5PnhKPRBK/DKVoZAQ6Ok1UmWI3BuWq6rdtrGJMUJem/GtR8+qG 22 | skip_symbols: true 23 | artifact: /artifacts\/packages\/.+\.nupkg/ 24 | on: 25 | branch: master 26 | -------------------------------------------------------------------------------- /aspectscope/sample/AspectCore.Extensions.AspectScope.Sample/AspectCore.Extensions.AspectScope.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /aspectscope/src/AspectCore.Extensions.AspectScope/AspectCore.Extensions.AspectScope.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | ScopedContext extension system for AspectCore Framework. 8 | AspectCore.Extensions.ScopedContext 9 | net45;netstandard1.6 10 | AspectCore.Extensions.AspectScope 11 | AspectCore.Extensions.AspectScope 12 | AspectCore.Extensions.AspectScope 13 | DynamicProxy;Aop;Aspect;AspectCore;Intercepter 14 | ScopedContext extension system for AspectCore Framework. 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /aspectscope/src/AspectCore.Extensions.AspectScope/IAspectScheduler.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Extensions.AspectScope 4 | { 5 | [NonAspect] 6 | public interface IAspectScheduler 7 | { 8 | bool TryEnter(AspectContext context); 9 | 10 | void Release(AspectContext context); 11 | 12 | bool TryRelate(AspectContext context, IInterceptor interceptor); 13 | 14 | AspectContext[] GetCurrentContexts(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /aspectscope/src/AspectCore.Extensions.AspectScope/IScopeInterceptor.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Extensions.AspectScope 4 | { 5 | [NonAspect] 6 | public interface IScopeInterceptor : IInterceptor 7 | { 8 | Scope Scope { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /aspectscope/src/AspectCore.Extensions.AspectScope/Scope.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.AspectScope 2 | { 3 | public enum Scope 4 | { 5 | None, 6 | 7 | Nested, 8 | 9 | Aspect 10 | } 11 | } -------------------------------------------------------------------------------- /aspectscope/src/AspectCore.Extensions.AspectScope/ScopeInterceptorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Extensions.AspectScope 5 | { 6 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] 7 | [NonAspect] 8 | public abstract class ScopeInterceptorAttribute : AbstractInterceptorAttribute, IScopeInterceptor 9 | { 10 | public virtual Scope Scope { get; set; } = Scope.None; 11 | } 12 | } -------------------------------------------------------------------------------- /aspectscope/src/AspectCore.Extensions.AspectScope/ServiceContainerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | using AspectCore.Injector; 4 | 5 | namespace AspectCore.Extensions.AspectScope 6 | { 7 | public static class ServiceContainerExtensions 8 | { 9 | public static IServiceContainer AddAspectScope(this IServiceContainer services) 10 | { 11 | if (services == null) 12 | { 13 | throw new ArgumentNullException(nameof(services)); 14 | } 15 | services.AddType(Lifetime.Scoped); 16 | services.AddType(Lifetime.Scoped); 17 | services.AddType(Lifetime.Scoped); 18 | return services; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /build/aspectcore.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/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/index.cake: -------------------------------------------------------------------------------- 1 | #load "./util.cake" 2 | #load "./version.cake" 3 | -------------------------------------------------------------------------------- /build/net45.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build/net46.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build/netstandard16.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.6.1 4 | 1.6.1 5 | 6 | -------------------------------------------------------------------------------- /build/netstandard20.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0.0-* 4 | 2.0.0-* 5 | 6 | -------------------------------------------------------------------------------- /build/sign.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | True 4 | $(MSBuildThisFileDirectory)aspectcore.snk 5 | False 6 | 7 | -------------------------------------------------------------------------------- /build/util.cake: -------------------------------------------------------------------------------- 1 | public class Util 2 | { 3 | public Util(ICakeContext context, BuildParameters build) 4 | { 5 | Context = context; 6 | Build = build; 7 | } 8 | 9 | public ICakeContext Context { get; set; } 10 | public BuildParameters Build { get; set; } 11 | 12 | public void PrintInfo() 13 | { 14 | Context.Information($@" 15 | Version: {Build.FullVersion()} 16 | Configuration: {Build.Configuration} 17 | "); 18 | } 19 | 20 | public static string CreateStamp() 21 | { 22 | var seconds = (long)(DateTime.UtcNow - new DateTime(2017, 1, 1)).TotalSeconds; 23 | return seconds.ToString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /build/version.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 4 5 | 0 6 | 7 | $(VersionMajor).$(VersionMinor).$(VersionPatch) 8 | 9 | 10 | -------------------------------------------------------------------------------- /core/README.md: -------------------------------------------------------------------------------- 1 | ## [AspectCore中的IoC容器和依赖注入](https://github.com/dotnetcore/AspectCore-Framework/blob/master/docs/injector.md) -------------------------------------------------------------------------------- /core/performance/AspectCore.Benchmark/AspectCore.Benchmark.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /core/performance/AspectCore.Benchmark/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using BenchmarkDotNet.Running; 3 | 4 | namespace AspectCore.Benchmark 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | //BenchmarkRunner.Run(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /core/performance/AspectCore.IoC.Benchmarks/AspectCore.IoC.Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /core/performance/AspectCore.IoC.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using BenchmarkDotNet.Running; 3 | 4 | namespace AspectCore.IoC.Benchmarks 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | BenchmarkRunner.Run(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Configuration/IAspectConfiguration.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | using AspectCore.Injector; 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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/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, Exception innerException) 10 | : base($"Exception has been thrown by the aspect of an invocation. ---> {innerException?.Message}.", innerException) 11 | { 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IAspectActivatorFactory.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.DynamicProxy 2 | { 3 | [NonAspect] 4 | public interface IAspectActivatorFactory 5 | { 6 | IAspectActivator Create(); 7 | } 8 | } -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/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 | -------------------------------------------------------------------------------- /core/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 factory); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IAspectCachingProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public interface IAspectCachingProvider : IDisposable 7 | { 8 | IAspectCaching GetAspectCaching(string name); 9 | } 10 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IAspectContextFactory.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.DynamicProxy 2 | { 3 | [NonAspect] 4 | public interface IAspectContextFactory 5 | { 6 | AspectContext CreateContext(AspectActivatorContext activatorContext); 7 | 8 | void ReleaseContext(AspectContext aspectContext); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IAspectValidationHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public interface IAspectValidationHandler 7 | { 8 | int Order { get; } 9 | 10 | bool Invoke(AspectValidationContext context, AspectValidationDelegate next); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IAspectValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public interface IAspectValidator 7 | { 8 | bool Validate(MethodInfo method, bool isStrictValidation); 9 | } 10 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IAspectValidatorBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.DynamicProxy 2 | { 3 | [NonAspect] 4 | public interface IAspectValidatorBuilder 5 | { 6 | IAspectValidator Build(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public interface IInterceptor 7 | { 8 | bool AllowMultiple { get; } 9 | 10 | bool Inherited { get; set; } 11 | 12 | int Order { get; set; } 13 | 14 | Task Invoke(AspectContext context, AspectDelegate next); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IInterceptorCollector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.DynamicProxy 5 | { 6 | [NonAspect] 7 | public interface IInterceptorCollector 8 | { 9 | IEnumerable Collect(MethodInfo serviceMethod, MethodInfo implementationMethod); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.DynamicProxy 5 | { 6 | [NonAspect] 7 | public interface IInterceptorSelector 8 | { 9 | IEnumerable Select(MethodInfo method); 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IProxyGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public interface IProxyGenerator : IDisposable 7 | { 8 | IProxyTypeGenerator TypeGenerator { get; } 9 | 10 | object CreateInterfaceProxy(Type serviceType); 11 | 12 | object CreateInterfaceProxy(Type serviceType, object implementationInstance); 13 | 14 | object CreateClassProxy(Type serviceType, Type implementationType, object[] args); 15 | } 16 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IProxyTypeGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public interface IProxyTypeGenerator 7 | { 8 | Type CreateInterfaceProxyType(Type serviceType); 9 | 10 | Type CreateInterfaceProxyType(Type serviceType, Type implementationType); 11 | 12 | Type CreateClassProxyType(Type serviceType, Type implementationType); 13 | } 14 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/IServiceInstanceAccessor.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.DynamicProxy 2 | { 3 | [NonAspect] 4 | public interface IServiceInstanceAccessor 5 | { 6 | object ServiceInstance { get; } 7 | } 8 | 9 | [NonAspect] 10 | public interface IServiceInstanceAccessor 11 | { 12 | TService ServiceInstance { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/NonAspectAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] 6 | public class NonAspectAttribute : Attribute 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/IParameterInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace AspectCore.DynamicProxy.Parameters 4 | { 5 | [NonAspect] 6 | public interface IParameterInterceptor 7 | { 8 | Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next); 9 | } 10 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/IParameterInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace AspectCore.DynamicProxy.Parameters 4 | { 5 | public interface IParameterInterceptorSelector 6 | { 7 | IParameterInterceptor[] Select(ParameterInfo parameter); 8 | } 9 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/ParameterAspectContext.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.DynamicProxy.Parameters 2 | { 3 | public struct ParameterAspectContext 4 | { 5 | public Parameter Parameter { get; } 6 | 7 | public AspectContext AspectContext { get; } 8 | 9 | public ParameterAspectContext(AspectContext aspectContext, Parameter parameter) 10 | { 11 | AspectContext = aspectContext; 12 | Parameter = parameter; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/ParameterAspectDelegate.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace AspectCore.DynamicProxy.Parameters 4 | { 5 | public delegate Task ParameterAspectDelegate(ParameterAspectContext context); 6 | } 7 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/ParameterInterceptorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AspectCore.DynamicProxy.Parameters 5 | { 6 | [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] 7 | public abstract class ParameterInterceptorAttribute : Attribute, IParameterInterceptor 8 | { 9 | public abstract Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next); 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/ReturnParameter.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace AspectCore.DynamicProxy.Parameters 4 | { 5 | internal sealed class ReturnParameter : Parameter 6 | { 7 | public override object Value 8 | { 9 | get 10 | { 11 | return _context.ReturnValue; 12 | } 13 | set 14 | { 15 | _context.ReturnValue = value; 16 | } 17 | } 18 | 19 | internal ReturnParameter(AspectContext context, ParameterInfo reflector) 20 | : base(context, -1, reflector) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/DynamicProxy/Parameters/ReturnParameterInterceptorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AspectCore.DynamicProxy.Parameters 5 | { 6 | [AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = false)] 7 | public abstract class ReturnParameterInterceptorAttribute : Attribute, IParameterInterceptor 8 | { 9 | public abstract Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next); 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/ConfigurationExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Configuration; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | public static class ConfigurationExtensions 7 | { 8 | public static IServiceContainer Configure(this IServiceContainer serviceContainer, Action configure) 9 | { 10 | if (serviceContainer == null) 11 | { 12 | throw new ArgumentNullException(nameof(serviceContainer)); 13 | } 14 | configure?.Invoke(serviceContainer.Configuration); 15 | return serviceContainer; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/Definitions/DelegateServiceDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Injector 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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/Definitions/InstanceServiceDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.Injector 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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/Definitions/ServiceDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Injector 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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/Definitions/TypeServiceDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.Injector 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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/FromContainerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] 6 | public class FromContainerAttribute : Attribute 7 | { 8 | public FromContainerAttribute() 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/ILifetimeServiceContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using AspectCore.DynamicProxy; 4 | 5 | namespace AspectCore.Injector 6 | { 7 | [NonAspect] 8 | public interface ILifetimeServiceContainer : 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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/IManyEnumerable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using AspectCore.DynamicProxy; 4 | 5 | namespace AspectCore.Injector 6 | { 7 | [NonAspect] 8 | public interface IManyEnumerable : IEnumerable, IEnumerable 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/IPropertyInjector.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | [NonAspect] 6 | public interface IPropertyInjector 7 | { 8 | void Invoke(object implementation); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/IPropertyInjectorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | [NonAspect] 7 | public interface IPropertyInjectorFactory 8 | { 9 | IPropertyInjector Create(Type implementationType); 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/IScopeResolverFactory.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | [NonAspect] 6 | public interface IScopeResolverFactory 7 | { 8 | IServiceResolver CreateScope(); 9 | } 10 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/IServiceContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using AspectCore.Configuration; 4 | using AspectCore.DynamicProxy; 5 | 6 | namespace AspectCore.Injector 7 | { 8 | [NonAspect] 9 | public interface IServiceContainer : IEnumerable 10 | { 11 | ILifetimeServiceContainer Singletons { get; } 12 | 13 | ILifetimeServiceContainer Scopeds { get; } 14 | 15 | ILifetimeServiceContainer Transients { get; } 16 | 17 | IAspectConfiguration Configuration { get; } 18 | 19 | int Count { get; } 20 | 21 | void Add(ServiceDefinition item); 22 | 23 | bool Contains(Type serviceType); 24 | } 25 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/IServiceResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | [NonAspect] 7 | public interface IServiceResolver : IServiceProvider, IDisposable 8 | { 9 | object Resolve(Type serviceType); 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/ITransientServiceAccessor.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | [NonAspect] 6 | public interface ITransientServiceAccessor where T : class 7 | { 8 | T Value { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Injector/Lifetime.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Injector 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 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Abstractions/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyTrademark("")] 11 | 12 | // Setting ComVisible to false makes the types in this assembly not visible 13 | // to COM components. If you need to access a type in this assembly from 14 | // COM, set the ComVisible attribute to true on that type. 15 | [assembly: ComVisible(false)] 16 | 17 | // The following GUID is for the ID of the typelib if this project is exposed to COM 18 | [assembly: Guid("f85d3075-97c2-4ac1-9b36-db752c0edbee")] -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Configuration/AspectConfiguration.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Injector; 2 | 3 | namespace AspectCore.Configuration 4 | { 5 | public sealed class AspectConfiguration : IAspectConfiguration 6 | { 7 | public AspectValidationHandlerCollection ValidationHandlers { get; } 8 | 9 | public InterceptorCollection Interceptors { get; } 10 | 11 | public NonAspectPredicateCollection NonAspectPredicates { get; } 12 | 13 | public AspectConfiguration() 14 | { 15 | ValidationHandlers = new AspectValidationHandlerCollection().AddDefault(this); 16 | Interceptors = new InterceptorCollection(); 17 | NonAspectPredicates = new NonAspectPredicateCollection().AddDefault(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Configuration/Extensions/AspectValidationHandlerCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Configuration 4 | { 5 | internal static class AspectValidationHandlerCollectionExtensions 6 | { 7 | internal static AspectValidationHandlerCollection AddDefault(this AspectValidationHandlerCollection aspectValidationHandlers, IAspectConfiguration configuration) 8 | { 9 | aspectValidationHandlers.Add(new OverwriteAspectValidationHandler()); 10 | aspectValidationHandlers.Add(new AttributeAspectValidationHandler()); 11 | aspectValidationHandlers.Add(new CacheAspectValidationHandler()); 12 | aspectValidationHandlers.Add(new ConfigureAspectValidationHandler(configuration)); 13 | return aspectValidationHandlers; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Configuration/InterceptorFactories/DelegateInterceptorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Configuration 5 | { 6 | public sealed class DelegateInterceptorFactory : InterceptorFactory 7 | { 8 | private readonly Func _aspectDelegate; 9 | private readonly int _order; 10 | 11 | public DelegateInterceptorFactory(Func aspectDelegate, int order, params AspectPredicate[] predicates) 12 | : base(predicates) 13 | { 14 | _aspectDelegate = aspectDelegate ?? throw new ArgumentNullException(nameof(aspectDelegate)); 15 | _order = order; 16 | } 17 | 18 | public override IInterceptor CreateInstance(IServiceProvider serviceProvider) 19 | { 20 | return new DelegateInterceptor(_aspectDelegate, _order); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/AspectActivatorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | public sealed class AspectActivatorFactory : IAspectActivatorFactory 7 | { 8 | private readonly IAspectContextFactory _aspectContextFactory; 9 | private readonly IAspectBuilderFactory _aspectBuilderFactory; 10 | 11 | public AspectActivatorFactory(IAspectContextFactory aspectContextFactory, IAspectBuilderFactory aspectBuilderFactory) 12 | { 13 | _aspectContextFactory = aspectContextFactory ?? throw new ArgumentNullException(nameof(aspectContextFactory)); 14 | _aspectBuilderFactory = aspectBuilderFactory ?? throw new ArgumentNullException(nameof(aspectBuilderFactory)); 15 | } 16 | 17 | public IAspectActivator Create() 18 | { 19 | return new AspectActivator(_aspectContextFactory, _aspectBuilderFactory); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/AspectCachingProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | 4 | namespace AspectCore.DynamicProxy 5 | { 6 | [NonAspect] 7 | public sealed class AspectCachingProvider : IAspectCachingProvider 8 | { 9 | private readonly ConcurrentDictionary _cachings; 10 | 11 | public AspectCachingProvider() 12 | { 13 | _cachings = new ConcurrentDictionary(); 14 | } 15 | 16 | public void Dispose() 17 | { 18 | foreach(var caching in _cachings) 19 | { 20 | caching.Value.Dispose(); 21 | } 22 | _cachings.Clear(); 23 | } 24 | 25 | public IAspectCaching GetAspectCaching(string name) 26 | { 27 | if (name == null) 28 | { 29 | throw new ArgumentNullException(nameof(name)); 30 | } 31 | return _cachings.GetOrAdd(name, key => new AspectCaching(key)); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/AttributeInterceptorSelector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using AspectCore.Extensions.Reflection; 4 | 5 | namespace AspectCore.DynamicProxy 6 | { 7 | [NonAspect] 8 | public sealed class AttributeInterceptorSelector : IInterceptorSelector 9 | { 10 | public IEnumerable Select(MethodInfo method) 11 | { 12 | foreach(var attribute in method.DeclaringType.GetTypeInfo().GetReflector().GetCustomAttributes()) 13 | { 14 | if (attribute is IInterceptor interceptor) 15 | yield return interceptor; 16 | } 17 | foreach (var attribute in method.GetReflector().GetCustomAttributes()) 18 | { 19 | if (attribute is IInterceptor interceptor) 20 | yield return interceptor; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/InterceptorSelectorEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AspectCore.DynamicProxy 4 | { 5 | [NonAspect] 6 | internal class InterceptorSelectorEqualityComparer : IEqualityComparer where T : class 7 | { 8 | public bool Equals(T x, T y) 9 | { 10 | if (x == null || y == null) 11 | { 12 | return false; 13 | } 14 | if (x == y) 15 | { 16 | return true; 17 | } 18 | if (x.GetType() == y.GetType()) 19 | { 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | public int GetHashCode(T obj) 26 | { 27 | return obj.GetType().GetHashCode(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/Parameters/EnableParameterAspectExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Configuration; 3 | 4 | namespace AspectCore.DynamicProxy.Parameters 5 | { 6 | public static class EnableParameterAspectExtensions 7 | { 8 | public static IAspectConfiguration EnableParameterAspect(this IAspectConfiguration configuration, params AspectPredicate[] predicates) 9 | { 10 | if (configuration == null) 11 | { 12 | throw new ArgumentNullException(nameof(configuration)); 13 | } 14 | configuration.Interceptors.AddTyped(predicates); 15 | return configuration; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/Parameters/NotNullAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AspectCore.DynamicProxy.Parameters 5 | { 6 | public class NotNullAttribute : ParameterInterceptorAttribute 7 | { 8 | public string Message { get; set; } 9 | 10 | public override Task Invoke(ParameterAspectContext context, ParameterAspectDelegate next) 11 | { 12 | if (context.Parameter.Value == null) 13 | { 14 | throw new ArgumentNullException(context.Parameter.Name, Message); 15 | } 16 | return next(context); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/ValidationHandlers/AttributeAspectValidationHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.DynamicProxy 5 | { 6 | [NonAspect] 7 | public sealed class AttributeAspectValidationHandler : IAspectValidationHandler 8 | { 9 | public int Order { get; } = 13; 10 | 11 | public bool Invoke(AspectValidationContext context, AspectValidationDelegate next) 12 | { 13 | var declaringType = context.Method.DeclaringType.GetTypeInfo(); 14 | 15 | if (IsAttributeAspect(declaringType) || IsAttributeAspect(context.Method)) 16 | { 17 | return true; 18 | } 19 | 20 | return next(context); 21 | } 22 | 23 | private bool IsAttributeAspect(MemberInfo member) 24 | { 25 | return member.CustomAttributes.Any(data => typeof(IInterceptor).GetTypeInfo().IsAssignableFrom(data.AttributeType)); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/DynamicProxy/ValidationHandlers/CacheAspectValidationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Reflection; 4 | 5 | namespace AspectCore.DynamicProxy 6 | { 7 | public sealed class CacheAspectValidationHandler : IAspectValidationHandler 8 | { 9 | private readonly ConcurrentDictionary detectorCache = new ConcurrentDictionary(); 10 | 11 | public int Order { get; } = -101; 12 | 13 | public bool Invoke(AspectValidationContext context, AspectValidationDelegate next) 14 | { 15 | return detectorCache.GetOrAdd(context, tuple => next(context)); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/EnumerableServiceDefintion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | internal class EnumerableServiceDefintion : ServiceDefinition 7 | { 8 | public IEnumerable ServiceDefinitions { get; } 9 | 10 | public Type ElementType { get; } 11 | 12 | public EnumerableServiceDefintion(Type serviceType, Type elementType, IEnumerable serviceDefinitions) : base(serviceType, Lifetime.Transient) 13 | { 14 | ElementType = elementType; 15 | ServiceDefinitions = serviceDefinitions; 16 | } 17 | } 18 | 19 | internal class ManyEnumerableServiceDefintion : EnumerableServiceDefintion 20 | { 21 | public ManyEnumerableServiceDefintion(Type serviceType, Type elementType, IEnumerable serviceDefinitions) : base(serviceType, elementType, serviceDefinitions) 22 | { 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/Extensions/LinkedListExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace AspectCore.Injector 6 | { 7 | internal static class LinkedListExtensions 8 | { 9 | public static LinkedList Add(this LinkedList linkedList, T value) 10 | { 11 | if (linkedList == null) 12 | { 13 | throw new ArgumentNullException(nameof(linkedList)); 14 | } 15 | if (value == null) 16 | { 17 | throw new ArgumentNullException(nameof(value)); 18 | } 19 | if (linkedList.Count == 0) linkedList.AddFirst(value); 20 | else linkedList.AddAfter(linkedList.Last, value); 21 | return linkedList; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/Extensions/ServiceContainerBuildExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | public static class ServiceContainerBuildExtensions 6 | { 7 | public static IServiceResolver Build(this IServiceContainer serviceContainer) 8 | { 9 | if (serviceContainer == null) 10 | { 11 | throw new ArgumentNullException(nameof(serviceContainer)); 12 | } 13 | return new ServiceResolver(serviceContainer); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/ManyEnumerable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | public sealed class ManyEnumerable : IManyEnumerable 7 | { 8 | private readonly IEnumerable _array; 9 | 10 | public ManyEnumerable(IEnumerable array) 11 | { 12 | _array = array; 13 | } 14 | 15 | public IEnumerator GetEnumerator() 16 | { 17 | return _array.GetEnumerator(); 18 | } 19 | 20 | IEnumerator IEnumerable.GetEnumerator() 21 | { 22 | return _array.GetEnumerator(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/PropertyInjector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | internal sealed class PropertyInjector : IPropertyInjector 6 | { 7 | private readonly IServiceProvider _serviceProvider; 8 | private readonly PropertyResolver[] _propertyResolvers; 9 | 10 | public PropertyInjector(IServiceProvider serviceProvider, PropertyResolver[] propertyResolvers) 11 | { 12 | _serviceProvider = serviceProvider; 13 | _propertyResolvers = propertyResolvers; 14 | } 15 | 16 | public void Invoke(object implementation) 17 | { 18 | if (implementation == null) 19 | { 20 | return; 21 | } 22 | var resolverLength = _propertyResolvers.Length; 23 | if (resolverLength == 0) 24 | { 25 | return; 26 | } 27 | for (var i = 0; i < resolverLength; i++) 28 | { 29 | _propertyResolvers[i].Resolve(_serviceProvider, implementation); 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/PropertyInjectorFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | [NonAspect] 7 | public class PropertyInjectorFactory : IPropertyInjectorFactory 8 | { 9 | private readonly IServiceProvider _servicePorvider; 10 | private readonly PropertyResolverSelector _propertyResolverSelector; 11 | 12 | public PropertyInjectorFactory(IServiceProvider servicePorvider) 13 | { 14 | _servicePorvider = servicePorvider; 15 | _propertyResolverSelector = PropertyResolverSelector.Default; 16 | } 17 | 18 | public IPropertyInjector Create(Type implementationType) 19 | { 20 | return new PropertyInjector(_servicePorvider, _propertyResolverSelector.SelectPropertyResolver(implementationType)); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/PropertyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Extensions.Reflection; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | public sealed class PropertyResolver 7 | { 8 | private readonly Func _propertyFactory; 9 | private readonly PropertyReflector _reflector; 10 | 11 | internal PropertyResolver(Func propertyFactory, PropertyReflector reflector) 12 | { 13 | _propertyFactory = propertyFactory; 14 | _reflector = reflector; 15 | } 16 | 17 | public void Resolve(IServiceProvider provider, object implementation) 18 | { 19 | _reflector.SetValue(implementation, _propertyFactory(provider)); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/ProxyServiceDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | internal class ProxyServiceDefinition : ServiceDefinition 7 | { 8 | public ServiceDefinition ServiceDefinition { get; } 9 | public TypeServiceDefinition ClassProxyServiceDefinition { get; } 10 | 11 | public ProxyServiceDefinition(ServiceDefinition serviceDefinition, Type proxyType) : base(serviceDefinition.ServiceType, serviceDefinition.Lifetime) 12 | { 13 | ProxyType = proxyType; 14 | ServiceDefinition = serviceDefinition; 15 | if (serviceDefinition.ServiceType.GetTypeInfo().IsClass) 16 | { 17 | ClassProxyServiceDefinition = new TypeServiceDefinition(serviceDefinition.ServiceType, ProxyType, serviceDefinition.Lifetime); 18 | } 19 | } 20 | 21 | public Type ProxyType { get; } 22 | } 23 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/ScopeResolverFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Injector 5 | { 6 | [NonAspect] 7 | internal class ScopeResolverFactory : IScopeResolverFactory 8 | { 9 | private readonly ServiceResolver _serviceResolver; 10 | 11 | public ScopeResolverFactory(IServiceResolver serviceResolver) 12 | { 13 | _serviceResolver = serviceResolver as ServiceResolver; 14 | } 15 | 16 | public IServiceResolver CreateScope() 17 | { 18 | if (_serviceResolver == null) 19 | { 20 | throw new ArgumentNullException("ServiceResolver"); 21 | } 22 | return new ServiceResolver(_serviceResolver._root ?? _serviceResolver); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Injector/TransientServiceAccessor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Injector 4 | { 5 | public sealed class TransientServiceAccessor : ITransientServiceAccessor where T : class 6 | { 7 | private readonly IServiceProvider _serviceProvider; 8 | public T Value => (T)_serviceProvider.GetService(typeof(T)); 9 | 10 | public TransientServiceAccessor(IServiceProvider serviceProvider) 11 | { 12 | _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore.Core")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("54ffb88e-6e90-4e57-886d-a8430039da23")] -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Utils/ActivatorUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Injector; 3 | 4 | namespace AspectCore.Utils 5 | { 6 | internal static class ActivatorUtils 7 | { 8 | public static object CreateManyEnumerable(Type elementType) 9 | { 10 | return Activator.CreateInstance(typeof(ManyEnumerable<>).MakeGenericType(elementType), Array.CreateInstance(elementType, 0)); 11 | } 12 | 13 | public static object CreateManyEnumerable(Type elementType, Array array) 14 | { 15 | return Activator.CreateInstance(typeof(ManyEnumerable<>).MakeGenericType(elementType), array); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Utils/ArrayUtils.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Utils 2 | { 3 | internal static class ArrayUtils 4 | { 5 | public static T[] Empty() 6 | { 7 | return EmptyArray.Value; 8 | } 9 | 10 | private static class EmptyArray 11 | { 12 | public static readonly T[] Value = new T[0]; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /core/src/AspectCore.Core/Utils/TaskUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace AspectCore.Utils 4 | { 5 | internal static class TaskUtils 6 | { 7 | internal static readonly Task CompletedTask = Task.FromResult(false); 8 | } 9 | 10 | internal static class TaskUtils 11 | { 12 | internal static readonly Task CompletedTask = Task.FromResult(default(T)); 13 | } 14 | } -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/AspectConfigurationTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using Xunit; 4 | 5 | namespace AspectCore.Abstractions.Internal.Test 6 | { 7 | public class AspectConfigureTest 8 | { 9 | [Fact] 10 | public void UseOption_Test() 11 | { 12 | var Configure = new AspectConfigure(); 13 | var userOption = Configure.GetConfigureOption(); 14 | Assert.NotNull(userOption); 15 | Assert.Empty(userOption); 16 | Func defaultOption = m => default(IInterceptor); 17 | userOption.Add(defaultOption); 18 | Assert.Contains(defaultOption, userOption); 19 | } 20 | 21 | [Fact] 22 | public void IgnoreOption_Test() 23 | { 24 | var Configure = new AspectConfigure(); 25 | var ignoreOption = Configure.GetConfigureOption(); 26 | Assert.NotNull(ignoreOption); 27 | Assert.NotEmpty(ignoreOption); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/ConfigurationOptionTest.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Abstractions; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | 9 | namespace AspectCore.Abstractions.Internal.Test 10 | { 11 | public class ConfigureOptionTest 12 | { 13 | [Fact] 14 | public void ConfigureOption_Add_Test() 15 | { 16 | IAspectConfigureOption ConfigureOption = new AspectConfigure().GetConfigureOption(); 17 | Func option = m => new object(); 18 | ConfigureOption.Add(option); 19 | Assert.Single(ConfigureOption, option); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/AspectValidatorFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AspectCore.Abstractions.Internal; 3 | 4 | namespace AspectCore.Abstractions.Test.Fakes 5 | { 6 | public class AspectValidatorFactory 7 | { 8 | public static IAspectValidator GetAspectValidator(IAspectConfigure configure) 9 | { 10 | var handlers = new List 11 | { 12 | new AccessibleAspectValidationHandler(), 13 | new AttributeAspectValidationHandler(), 14 | new CacheAspectValidationHandler(), 15 | new GlobalAspectValidationHandler(configure), 16 | new DynamicallyAspectValidationHandler(), 17 | new IgnoreAspectValidationHandler(configure), 18 | new NonAspectValidationHandler() 19 | }; 20 | var aspectValidatorBuilder = new AspectValidatorBuilder(handlers); 21 | return aspectValidatorBuilder.Build(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/DescriptorWithParameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Reflection; 4 | 5 | namespace AspectCore.Abstractions.Test 6 | { 7 | public class DescriptorWithParameter 8 | { 9 | public static readonly MethodInfo Method = typeof(DescriptorWithParameter).GetTypeInfo().DeclaredMethods.Where(m => m.Name == "TestMethodWithParameter").First(); 10 | public static readonly MethodInfo InvokeMethod = typeof(DescriptorWithParameter).GetTypeInfo().DeclaredMethods.Where(m => m.Name == "Invoke").First(); 11 | 12 | public static readonly ParameterInfo[] Parameters = Method.GetParameters(); 13 | 14 | public static readonly ParameterInfo ReturnParameter = Method.ReturnParameter; 15 | 16 | public void TestMethodWithParameter(int age, string name, object obj) 17 | { 18 | } 19 | 20 | public object Invoke(object obj) 21 | { 22 | return obj; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/ITargetService.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Abstractions.Internal.Test.Fakes 2 | { 3 | public interface ITargetService 4 | { 5 | [Increment] 6 | int Add(int value); 7 | } 8 | 9 | [Increment] 10 | public interface ITargetService 11 | { 12 | 13 | [Increment] 14 | T Add(T value); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/IValidatorModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Abstractions.Internal.Test.Fakes 7 | { 8 | public interface IValidatorModel 9 | { 10 | void Validate(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/IncrementAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Abstractions.Internal.Test.Fakes 7 | { 8 | public class IncrementAttribute : InterceptorAttribute 9 | { 10 | public async override Task Invoke(Abstractions.AspectContext context, AspectDelegate next) 11 | { 12 | await next(context); 13 | if (context.ReturnParameter.ParameterType == typeof(int)) 14 | { 15 | int value; 16 | if(int.TryParse(context.ReturnParameter.Value.ToString(), out value)) 17 | { 18 | value = value + 1; 19 | context.ReturnParameter.Value = value; 20 | } 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/InjectedInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AspectCore.Abstractions.Internal.Test.Fakes 5 | { 6 | public class InjectedInterceptor : IInterceptor 7 | { 8 | [FromServices] 9 | public IAspectConfigure Configure { get; set; } 10 | 11 | [FromServices] 12 | public IAspectConfigure ConfigureWithNoSet { get; } 13 | 14 | public IAspectConfigure ConfigureWithNoFromServicesAttribute { get; set; } 15 | 16 | public bool AllowMultiple { get; } 17 | 18 | public int Order { get; set; } 19 | 20 | public Task Invoke(Abstractions.AspectContext context, AspectDelegate next) 21 | { 22 | return next(context); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/InstanceServiceProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Abstractions.Internal.Test.Fakes 4 | { 5 | public class InstanceServiceProvider : IServiceInstanceProvider, IServiceProvider 6 | { 7 | private readonly object instance; 8 | 9 | public InstanceServiceProvider(object instance) 10 | { 11 | this.instance = instance; 12 | } 13 | 14 | public object GetInstance(Type serviceType) 15 | { 16 | return instance; 17 | } 18 | 19 | public object GetService(Type serviceType) 20 | { 21 | return instance; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/InstanceSupportOriginalService.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Abstractions.Internal.Test.Fakes 2 | { 3 | public class InstanceSupportOriginalService: InstanceServiceProvider, IRealServiceProvider 4 | { 5 | public InstanceSupportOriginalService(object instance) : base(instance) 6 | { 7 | } 8 | 9 | public void Dispose() 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/InterceptorMatcherModel.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Abstractions.Internal.Test.Fakes 2 | { 3 | public class InterceptorMatcherModel 4 | { 5 | [MatcherTest] 6 | public void WithInterceptor() 7 | { 8 | } 9 | 10 | public void WithOutInterceptor() 11 | { 12 | } 13 | 14 | public void ConfigureInterceptor() 15 | { 16 | } 17 | } 18 | 19 | [MatcherTest] 20 | public class WithInterceptorMatcherModel 21 | { 22 | public void WithOutInterceptor() 23 | { 24 | } 25 | } 26 | 27 | [MatcherTest, MultipMatcherTest] 28 | public class MultipWithInterceptorMatcherModel 29 | { 30 | [MultipMatcherTest] 31 | public void MultipWithInterceptor() 32 | { 33 | } 34 | 35 | [MatcherTest] 36 | public void WithInterceptor() 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/ItemInterceptorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Abstractions.Test.Fakes 7 | { 8 | public class ItemInterceptorAttribute : InterceptorAttribute 9 | { 10 | public override Task Invoke(AspectContext context, AspectDelegate next) 11 | { 12 | context.Items.Add("key", "ItemInterceptor"); 13 | return base.Invoke(context, next); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/MatcherTestAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Abstractions.Internal.Test.Fakes 7 | { 8 | public class MatcherTestAttribute : InterceptorAttribute 9 | { 10 | public override Task Invoke(Abstractions.AspectContext context, AspectDelegate next) 11 | { 12 | return next(context); 13 | } 14 | } 15 | 16 | public class MultipMatcherTestAttribute : InterceptorAttribute 17 | { 18 | public override bool AllowMultiple 19 | { 20 | get 21 | { 22 | return true; 23 | } 24 | } 25 | 26 | public override Task Invoke(Abstractions.AspectContext context, AspectDelegate next) 27 | { 28 | return next(context); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/OriginalServiceProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Abstractions.Test.Fakes 7 | { 8 | public class OriginalServiceProvider : IRealServiceProvider 9 | { 10 | private readonly object instance; 11 | public OriginalServiceProvider(object instance) 12 | { 13 | this.instance = instance; 14 | } 15 | 16 | public object GetService(Type serviceType) 17 | { 18 | return instance; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/ProxyService.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Abstractions.Internal.Test.Fakes 2 | { 3 | public class ProxyService : TargetService 4 | { 5 | public override int Add(int value) 6 | { 7 | return base.Add(value); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Fakes/TargetService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Abstractions.Internal.Test.Fakes 4 | { 5 | public class TargetService : AbsTargetService, ITargetService 6 | { 7 | public override int Add(int value) 8 | { 9 | return value; 10 | } 11 | } 12 | 13 | public class TargetService : ITargetService 14 | { 15 | public T Add(T value) 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | 21 | [Increment] 22 | public class AbsTargetService 23 | { 24 | public virtual int Add(int value) 25 | { 26 | return value; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/MatchTest.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Abstractions.Internal; 2 | using Xunit; 3 | 4 | namespace AspectCore.Abstractions.Test 5 | { 6 | public class MatchTest 7 | { 8 | [Theory] 9 | [InlineData("*")] 10 | [InlineData("AspectCore.Abstractions.*")] 11 | [InlineData("*.Abstractions.*")] 12 | [InlineData("*.Abstractions.Test")] 13 | [InlineData("AspectCore.Abstractions.Test")] 14 | public void Match_True_Test(string vaule) 15 | { 16 | const string fake = "AspectCore.Abstractions.Test"; 17 | Assert.True(fake.Matches(vaule)); 18 | } 19 | 20 | [Theory] 21 | [InlineData("AspectCore.Abstractions.Test1")] 22 | [InlineData("AspectCore.Abstractions.")] 23 | [InlineData("AspectCore.Lite.*.Abstractions.Test")] 24 | [InlineData("*.AspectCore.Abstractions.Test")] 25 | public void Match_False_Test(string vaule) 26 | { 27 | const string fake = "AspectCore.Abstractions.Test"; 28 | Assert.False(fake.Matches(vaule)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/MethodAccessorTest.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Abstractions.Internal; 2 | using System.Reflection; 3 | using Xunit; 4 | 5 | namespace AspectCore.Abstractions.Test 6 | { 7 | public class MethodAccessorTest 8 | { 9 | public object TestMethod() 10 | { 11 | return "test"; 12 | } 13 | 14 | [Fact] 15 | public void MethodAccessorInvoker_Test() 16 | { 17 | var methodInfo = typeof(MethodAccessorTest).GetTypeInfo().GetMethod("TestMethod"); 18 | var methodAccessor = new MethodAccessor(methodInfo); 19 | var methodInvoker = methodAccessor.CreateMethodInvoker(); 20 | Assert.Equal(methodInvoker.Invoke(this, EmptyArray.Value), TestMethod()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore.Abstractions.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("3584da47-63ed-4379-9ecc-3888c6b2a7d5")] 20 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/PropertyAccessorTest.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Abstractions.Internal; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | 9 | namespace AspectCore.Abstractions.Test 10 | { 11 | public class PropertyAccessorTest 12 | { 13 | public string Name { get; set; } 14 | 15 | [Fact] 16 | public void Setter_Test() 17 | { 18 | var property = typeof(PropertyAccessorTest).GetTypeInfo().GetProperty("Name"); 19 | 20 | new PropertyAccessor(property).CreatePropertySetter()(this, "Test"); 21 | 22 | Assert.Equal(Name, "Test"); 23 | } 24 | 25 | [Fact] 26 | public void Getter_Test() 27 | { 28 | var property = typeof(PropertyAccessorTest).GetTypeInfo().GetProperty("Name"); 29 | 30 | Name = "Test"; 31 | 32 | var name = new PropertyAccessor(property).CreatePropertyGetter()(this); 33 | 34 | Assert.Equal(Name, name); 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/ProxyDescriptorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Xunit; 6 | 7 | namespace AspectCore.Abstractions.Test 8 | { 9 | public class ProxyDescriptorTest 10 | { 11 | [Fact] 12 | public void Test_Property() 13 | { 14 | object impInstance = new DescriptorWithParameter(); 15 | 16 | ProxyDescriptor descriptor = new ProxyDescriptor(impInstance, DescriptorWithParameter.Method, typeof(DescriptorWithParameter)); 17 | 18 | Assert.Equal(descriptor.ProxyInstance, impInstance); 19 | Assert.Equal(descriptor.ProxyMethod, DescriptorWithParameter.Method); 20 | Assert.Equal(descriptor.ProxyType, typeof(DescriptorWithParameter)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/ReturnParameterDescriptorTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Xunit; 6 | 7 | namespace AspectCore.Abstractions.Test 8 | { 9 | public class ReturnParameterDescriptorTest 10 | { 11 | [Fact] 12 | public void Value_Set_Void() 13 | { 14 | var returnParemater = new ReturnParameterDescriptor(null, DescriptorWithParameter.ReturnParameter); 15 | returnParemater.Value = new object(); 16 | Assert.Null(returnParemater.Value); 17 | } 18 | 19 | [Fact] 20 | public void Value_Get_Void() 21 | { 22 | var returnParemater = new ReturnParameterDescriptor(new object(), DescriptorWithParameter.ReturnParameter); 23 | Assert.Null(returnParemater.Value); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/ServiceProviderAccessorTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Abstractions.Internal.Test.Fakes; 3 | using AspectCore.Abstractions.Test.Fakes; 4 | using Xunit; 5 | 6 | namespace AspectCore.Abstractions.Internal.Test 7 | { 8 | public class ServiceProviderAccessorTests 9 | { 10 | [Fact] 11 | public void get_ServiceProvider_Test() 12 | { 13 | var generator = new ProxyGenerator(AspectValidatorFactory.GetAspectValidator(new AspectConfigure())); 14 | var proxyType = generator.CreateInterfaceProxyType(typeof(ITargetService), typeof(TargetService)); 15 | var serviceProvider = new InstanceServiceProvider(null); 16 | var proxyInstance = Activator.CreateInstance(proxyType, serviceProvider, new InstanceServiceProvider(new TargetService())); 17 | 18 | var serviceProviderAccessor = proxyInstance as IServiceProviderAccessor; 19 | Assert.NotNull(serviceProviderAccessor); 20 | Assert.Equal(serviceProviderAccessor.ServiceProvider, serviceProvider); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/test/AspectCore.Abstractions.Test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "debugType": "portable" 5 | }, 6 | "dependencies": { 7 | "System.Runtime.Serialization.Primitives": "4.3.0", 8 | "xunit": "2.1.0", 9 | "dotnet-test-xunit": "2.2.0-preview2-build1029", 10 | "System.Reflection": "4.3.0", 11 | "System.Linq": "4.3.0", 12 | "NSubstitute": "2.0.1-rc", 13 | "AspectCore.Abstractions": "1.1.0-*", 14 | "AspectCore.Core": "1.1.0-rc1-13272" 15 | }, 16 | "testRunner": "xunit", 17 | "frameworks": { 18 | "netcoreapp1.1": { 19 | "dependencies": { 20 | "Microsoft.NETCore.App": { 21 | "type": "platform", 22 | "version": "1.1.0" 23 | } 24 | }, 25 | "imports": [ 26 | "dotnet5.4", 27 | "portable-net451+win8" 28 | ] 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/AspectCore.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp2.0 4 | false 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/DynamicProxy/AsyncAspectTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using AspectCore.DynamicProxy; 4 | using System.Text; 5 | using Xunit; 6 | using System.Threading.Tasks; 7 | 8 | namespace AspectCore.Tests.DynamicProxy 9 | { 10 | public class AsyncAspectTests : DynamicProxyTestBase 11 | { 12 | [Fact] 13 | public void DynAsync_Test() 14 | { 15 | var proxy = ProxyGenerator.CreateClassProxy(); 16 | var result = proxy.DynAsync(100); 17 | Assert.IsAssignableFrom>(result); 18 | } 19 | 20 | [Fact] 21 | public void Async_Test() 22 | { 23 | var proxy = ProxyGenerator.CreateClassProxy(); 24 | var result = proxy.Async(100); 25 | Assert.IsAssignableFrom>(result); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/DynamicProxy/DynamicProxyTestBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.Configuration; 5 | using AspectCore.DynamicProxy; 6 | 7 | namespace AspectCore.Tests.DynamicProxy 8 | { 9 | public class DynamicProxyTestBase 10 | { 11 | protected IProxyGenerator ProxyGenerator { get; } 12 | 13 | public DynamicProxyTestBase() 14 | { 15 | var builder = new ProxyGeneratorBuilder(); 16 | builder.Configure(Configure); 17 | ProxyGenerator = builder.Build(); 18 | } 19 | 20 | protected virtual void Configure(IAspectConfiguration configuration) { } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/DynamicProxy/OpenGenericMethodTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.Configuration; 5 | using AspectCore.DynamicProxy; 6 | using Microsoft.Extensions.ObjectPool; 7 | using Xunit; 8 | 9 | namespace AspectCore.Tests.DynamicProxy 10 | { 11 | public class OpenGenericMethodTests : DynamicProxyTestBase 12 | { 13 | [Fact] 14 | public void OpenGenericProxy() 15 | { 16 | var proxy = ProxyGenerator.CreateClassProxy(); 17 | 18 | } 19 | 20 | 21 | protected override void Configure(IAspectConfiguration configuration) 22 | { 23 | configuration.Interceptors.AddDelegate((ctx, next) => next(ctx)); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/DynamicProxy/ParameterInjectionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using AspectCore.Configuration; 4 | using AspectCore.DynamicProxy; 5 | using AspectCore.DynamicProxy.Parameters; 6 | using Xunit; 7 | 8 | namespace AspectCore.Tests.DynamicProxy 9 | { 10 | public class ParameterInjectionTest : DynamicProxyTestBase 11 | { 12 | [Fact] 13 | public void Parameter_Intercept() 14 | { 15 | var service = ProxyGenerator.CreateClassProxy(); 16 | Assert.Throws(() => 17 | { 18 | service.Run(null); 19 | }); 20 | } 21 | 22 | protected override void Configure(IAspectConfiguration configuration) 23 | { 24 | configuration.Interceptors.AddTyped(); 25 | } 26 | } 27 | 28 | public class AppService 29 | { 30 | public virtual void Run([NotNull]string name) 31 | { 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/Injector/InjectorTestBase.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Injector; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Tests.Injector 5 | { 6 | public class InjectorTestBase 7 | { 8 | public IServiceResolver ServiceResolver { get; } 9 | 10 | public IServiceContainer ServiceContainer { get; } 11 | 12 | public InjectorTestBase() 13 | { 14 | ServiceContainer = new ServiceContainer(); 15 | ConfigureService(ServiceContainer); 16 | ServiceResolver = ServiceContainer.Build(); 17 | } 18 | 19 | protected virtual void ConfigureService(IServiceContainer serviceContainer) { } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /core/test/AspectCore.Tests/Integrate/IntegrateTestBase.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Configuration; 2 | using AspectCore.DynamicProxy; 3 | using AspectCore.Injector; 4 | 5 | namespace AspectCore.Tests.Integrate 6 | { 7 | public class IntegrateTestBase 8 | { 9 | public IServiceResolver ServiceResolver { get; } 10 | 11 | public IServiceContainer ServiceContainer { get; } 12 | 13 | public IntegrateTestBase() 14 | { 15 | ServiceContainer = new ServiceContainer(); 16 | ServiceContainer.Configure(Configure); 17 | ConfigureService(ServiceContainer); 18 | ServiceResolver = ServiceContainer.Build(); 19 | } 20 | 21 | protected virtual void ConfigureService(IServiceContainer serviceContainer) { } 22 | 23 | protected virtual void Configure(IAspectConfiguration configuration) { } 24 | } 25 | } -------------------------------------------------------------------------------- /datavalidation/sample/AspectCore.Extensions.DataAnnotations.Sample/AspectCore.Extensions.DataAnnotations.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | DataAnnotations.Sample 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /datavalidation/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 | } 12 | 13 | public class AccountService : IAccountService 14 | { 15 | public IDataState DataState { get; set; } 16 | 17 | public void Register(RegisterInput input) 18 | { 19 | if (DataState.IsValid) 20 | { 21 | //验证通过 22 | Console.WriteLine("register.. name:{0},email:{1}", input.Name, input.Email); 23 | } 24 | 25 | if (!DataState.IsValid) 26 | { 27 | //验证失败 28 | foreach(var error in DataState.Errors) 29 | { 30 | Console.WriteLine("error.. key:{0},message:{1}", error.Key, error.ErrorMessage); 31 | } 32 | } 33 | Console.WriteLine(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /datavalidation/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 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataAnnotations/AspectCore.Extensions.DataAnnotations.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | DataAnnotations extension system for AspectCore Framework. 8 | AspectCore.Extensions.DataAnnotations 9 | netstandard1.6;net45 10 | AspectCore.Extensions.DataAnnotations 11 | AspectCore.Extensions.DataAnnotations 12 | DataValidation;DataAnnotations;AspectCore;AOP 13 | DataAnnotations extension system for AspectCore Framework. 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataAnnotations/ServiceContainerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Configuration; 3 | using AspectCore.Extensions.DataValidation; 4 | using AspectCore.Injector; 5 | 6 | namespace AspectCore.Extensions.DataAnnotations 7 | { 8 | public static class ServiceContainerExtensions 9 | { 10 | public static IServiceContainer AddDataAnnotations(this IServiceContainer services, params AspectPredicate[] predicates) 11 | { 12 | if (services == null) 13 | { 14 | throw new ArgumentNullException(nameof(services)); 15 | } 16 | services.AddType(); 17 | services.AddType(); 18 | services.AddType(); 19 | services.Configuration.Interceptors.AddTyped(predicates); 20 | return services; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/DataMetaData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AspectCore.DynamicProxy.Parameters; 4 | using AspectCore.Extensions.Reflection; 5 | using System.ComponentModel.DataAnnotations; 6 | 7 | namespace AspectCore.Extensions.DataValidation 8 | { 9 | public sealed class DataMetaData 10 | { 11 | public Type Type { get; } 12 | 13 | public Attribute[] Attributes { get; } 14 | 15 | public object Value { get; } 16 | 17 | public DataValidationErrorCollection Errors { get; } 18 | 19 | public DataValidationState State { get; set; } 20 | 21 | public DataMetaData(Parameter paramter) 22 | { 23 | Type = paramter.Type; 24 | Value = paramter.Value; 25 | Attributes = paramter.ParameterInfo.GetReflector().GetCustomAttributes(); 26 | Errors = new DataValidationErrorCollection(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/DataState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace AspectCore.Extensions.DataValidation 6 | { 7 | internal class DataState : IDataState 8 | { 9 | private readonly bool _isDataValid; 10 | 11 | public bool IsValid 12 | { 13 | get 14 | { 15 | return _isDataValid && Errors.Count == 0; 16 | } 17 | } 18 | 19 | public DataValidationErrorCollection Errors { get; } 20 | 21 | public DataState(bool isValid, DataValidationErrorCollection dataValidationErrors) 22 | { 23 | _isDataValid = isValid; 24 | Errors = dataValidationErrors ?? throw new ArgumentNullException(nameof(dataValidationErrors)); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/DataStateFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace AspectCore.Extensions.DataValidation 4 | { 5 | public class DataStateFactory : IDataStateFactory 6 | { 7 | public IDataState CreateDataState(DataValidationContext dataValidationContext) 8 | { 9 | var dataValidationErrors = new DataValidationErrorCollection(); 10 | foreach (var error in dataValidationContext.DataMetaDatas.SelectMany(x => x.Errors)) 11 | dataValidationErrors.Add(error); 12 | var isValid = dataValidationContext.DataMetaDatas.All(x => x.State != DataValidationState.Invalid); 13 | return new DataState(isValid, dataValidationErrors); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/DataValidationContext.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using AspectCore.DynamicProxy; 4 | using AspectCore.DynamicProxy.Parameters; 5 | 6 | namespace AspectCore.Extensions.DataValidation 7 | { 8 | public sealed class DataValidationContext 9 | { 10 | public IEnumerable DataMetaDatas { get; } 11 | 12 | public AspectContext AspectContext { get; } 13 | 14 | public DataValidationContext(AspectContext aspectContext) 15 | { 16 | AspectContext = aspectContext; 17 | DataMetaDatas = aspectContext.GetParameters().Select(param => new DataMetaData(param)).ToArray(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/DataValidationError.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Extensions.DataValidation 4 | { 5 | public sealed class DataValidationError 6 | { 7 | public string Key { get; } 8 | 9 | public string ErrorMessage { get; } 10 | 11 | public Exception Exception { get; } 12 | 13 | public DataValidationError(string key, string errorMessage) 14 | { 15 | Key = key ?? string.Empty; 16 | ErrorMessage = errorMessage ?? string.Empty; 17 | } 18 | 19 | public DataValidationError(string key, Exception exception) 20 | : this(key, null, exception) 21 | { 22 | } 23 | 24 | public DataValidationError(string key, string errorMessage, Exception exception) 25 | : this(key, errorMessage) 26 | { 27 | if (exception == null) 28 | { 29 | throw new ArgumentNullException(nameof(exception)); 30 | } 31 | 32 | Exception = exception; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/DataValidationState.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.DataValidation 2 | { 3 | public enum DataValidationState 4 | { 5 | Unvalidated, 6 | Invalid, 7 | Valid, 8 | Skipped 9 | } 10 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/IDataState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.DynamicProxy; 5 | 6 | namespace AspectCore.Extensions.DataValidation 7 | { 8 | [NonAspect] 9 | public interface IDataState 10 | { 11 | bool IsValid { get; } 12 | 13 | DataValidationErrorCollection Errors { get; } 14 | } 15 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/IDataStateFactory.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Extensions.DataValidation 4 | { 5 | [NonAspect] 6 | public interface IDataStateFactory 7 | { 8 | IDataState CreateDataState(DataValidationContext dataValidationContext); 9 | } 10 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/IDataStateProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using AspectCore.DynamicProxy; 5 | 6 | namespace AspectCore.Extensions.DataValidation 7 | { 8 | [NonAspect] 9 | public interface IDataStateProvider 10 | { 11 | IDataState DataState { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/IDataValidator.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Extensions.DataValidation 4 | { 5 | [NonAspect] 6 | public interface IDataValidator 7 | { 8 | void Validate(DataValidationContext context); 9 | } 10 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/IPropertyValidator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Extensions.DataValidation 5 | { 6 | [NonAspect] 7 | public interface IPropertyValidator 8 | { 9 | IEnumerable Validate(PropertyValidationContext propertyValidationContext); 10 | } 11 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/PropertyValidationContext.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | 3 | namespace AspectCore.Extensions.DataValidation 4 | { 5 | public sealed class PropertyValidationContext 6 | { 7 | public PropertyMetaData PropertyMetaData { get; } 8 | 9 | public AspectContext AspectContext { get; } 10 | 11 | public PropertyValidationContext(PropertyMetaData propertyMetaData, AspectContext aspectContext) 12 | { 13 | PropertyMetaData = propertyMetaData; 14 | AspectContext = aspectContext; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /datavalidation/src/AspectCore.Extensions.DataValidation/SkipValidationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Extensions.DataValidation 4 | { 5 | public class SkipValidationAttribute : Attribute 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "wwwroot/lib" 3 | } 4 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using AspNetCore.Sample.Models; 8 | 9 | namespace AspNetCore.Sample.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | return View(); 16 | } 17 | 18 | public IActionResult About() 19 | { 20 | ViewData["Message"] = "Your application description page."; 21 | 22 | return View(); 23 | } 24 | 25 | public IActionResult Contact() 26 | { 27 | ViewData["Message"] = "Your contact page."; 28 | 29 | return View(); 30 | } 31 | 32 | public IActionResult Error() 33 | { 34 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 6 | using Microsoft.EntityFrameworkCore; 7 | using AspNetCore.Sample.Models; 8 | using AspectCore.DynamicProxy; 9 | 10 | namespace AspNetCore.Sample.Data 11 | { 12 | //[NonAspect] 13 | public class ApplicationDbContext : IdentityDbContext 14 | { 15 | public ApplicationDbContext(DbContextOptions options) 16 | : base(options) 17 | { 18 | } 19 | 20 | protected override void OnModelCreating(ModelBuilder builder) 21 | { 22 | base.OnModelCreating(builder); 23 | // Customize the ASP.NET Identity model and override the defaults if needed. 24 | // For example, you can rename the ASP.NET Identity table names and more. 25 | // Add your customizations after calling base.OnModelCreating(builder); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Extensions/EmailSenderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text.Encodings.Web; 5 | using System.Threading.Tasks; 6 | using AspNetCore.Sample.Services; 7 | 8 | namespace AspNetCore.Sample.Services 9 | { 10 | public static class EmailSenderExtensions 11 | { 12 | public static Task SendEmailConfirmationAsync(this IEmailSender emailSender, string email, string link) 13 | { 14 | return emailSender.SendEmailAsync(email, "Confirm your email", 15 | $"Please confirm your account by clicking this link: link"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Extensions/UrlHelperExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AspNetCore.Sample.Controllers; 6 | 7 | namespace Microsoft.AspNetCore.Mvc 8 | { 9 | public static class UrlHelperExtensions 10 | { 11 | public static string EmailConfirmationLink(this IUrlHelper urlHelper, string userId, string code, string scheme) 12 | { 13 | return urlHelper.Action( 14 | action: nameof(AccountController.ConfirmEmail), 15 | controller: "Account", 16 | values: new { userId, code }, 17 | protocol: scheme); 18 | } 19 | 20 | public static string ResetPasswordCallbackLink(this IUrlHelper urlHelper, string userId, string code, string scheme) 21 | { 22 | return urlHelper.Action( 23 | action: nameof(AccountController.ResetPassword), 24 | controller: "Account", 25 | values: new { userId, code }, 26 | protocol: scheme); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/ExternalLoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class ExternalLoginViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/ForgotPasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class ForgotPasswordViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class LoginViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | 15 | [Required] 16 | [DataType(DataType.Password)] 17 | public string Password { get; set; } 18 | 19 | [Display(Name = "Remember me?")] 20 | public bool RememberMe { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/LoginWith2faViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class LoginWith2faViewModel 10 | { 11 | [Required] 12 | [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 13 | [DataType(DataType.Text)] 14 | [Display(Name = "Authenticator code")] 15 | public string TwoFactorCode { get; set; } 16 | 17 | [Display(Name = "Remember this machine")] 18 | public bool RememberMachine { get; set; } 19 | 20 | public bool RememberMe { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/LoginWithRecoveryCodeViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class LoginWithRecoveryCodeViewModel 10 | { 11 | [Required] 12 | [DataType(DataType.Text)] 13 | [Display(Name = "Recovery Code")] 14 | public string RecoveryCode { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/RegisterViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class RegisterViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | [Display(Name = "Email")] 14 | public string Email { get; set; } 15 | 16 | [Required] 17 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 18 | [DataType(DataType.Password)] 19 | [Display(Name = "Password")] 20 | public string Password { get; set; } 21 | 22 | [DataType(DataType.Password)] 23 | [Display(Name = "Confirm password")] 24 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 25 | public string ConfirmPassword { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/AccountViewModels/ResetPasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.AccountViewModels 8 | { 9 | public class ResetPasswordViewModel 10 | { 11 | [Required] 12 | [EmailAddress] 13 | public string Email { get; set; } 14 | 15 | [Required] 16 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 17 | [DataType(DataType.Password)] 18 | public string Password { get; set; } 19 | 20 | [DataType(DataType.Password)] 21 | [Display(Name = "Confirm password")] 22 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 23 | public string ConfirmPassword { get; set; } 24 | 25 | public string Code { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ApplicationUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity; 6 | 7 | namespace AspNetCore.Sample.Models 8 | { 9 | // Add profile data for application users by adding properties to the ApplicationUser class 10 | public class ApplicationUser : IdentityUser 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/CreateBookViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace AspNetCore.Sample.Models 4 | { 5 | public class CreateBookViewModel 6 | { 7 | public string Name { get; set; } 8 | 9 | public string Author { get; set; } 10 | } 11 | 12 | public class CreateBookDto 13 | { 14 | [Required] 15 | public string Name { get; set; } 16 | 17 | [Required] 18 | public string Author { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspNetCore.Sample.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/EnableAuthenticatorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | 8 | namespace AspNetCore.Sample.Models.ManageViewModels 9 | { 10 | public class EnableAuthenticatorViewModel 11 | { 12 | [Required] 13 | [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 14 | [DataType(DataType.Text)] 15 | [Display(Name = "Verification Code")] 16 | public string Code { get; set; } 17 | 18 | [ReadOnly(true)] 19 | public string SharedKey { get; set; } 20 | 21 | public string AuthenticatorUri { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/ExternalLoginsViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authentication; 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | namespace AspNetCore.Sample.Models.ManageViewModels 9 | { 10 | public class ExternalLoginsViewModel 11 | { 12 | public IList CurrentLogins { get; set; } 13 | 14 | public IList OtherLogins { get; set; } 15 | 16 | public bool ShowRemoveButton { get; set; } 17 | 18 | public string StatusMessage { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/GenerateRecoveryCodesViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.ManageViewModels 8 | { 9 | public class GenerateRecoveryCodesViewModel 10 | { 11 | public string[] RecoveryCodes { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/IndexViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.ManageViewModels 8 | { 9 | public class IndexViewModel 10 | { 11 | public string Username { get; set; } 12 | 13 | public bool IsEmailConfirmed { get; set; } 14 | 15 | [Required] 16 | [EmailAddress] 17 | public string Email { get; set; } 18 | 19 | [Phone] 20 | [Display(Name = "Phone number")] 21 | public string PhoneNumber { get; set; } 22 | 23 | public string StatusMessage { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/RemoveLoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.ManageViewModels 8 | { 9 | public class RemoveLoginViewModel 10 | { 11 | public string LoginProvider { get; set; } 12 | public string ProviderKey { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/SetPasswordViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.ManageViewModels 8 | { 9 | public class SetPasswordViewModel 10 | { 11 | [Required] 12 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 13 | [DataType(DataType.Password)] 14 | [Display(Name = "New password")] 15 | public string NewPassword { get; set; } 16 | 17 | [DataType(DataType.Password)] 18 | [Display(Name = "Confirm new password")] 19 | [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] 20 | public string ConfirmPassword { get; set; } 21 | 22 | public string StatusMessage { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Models/ManageViewModels/TwoFactorAuthenticationViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspNetCore.Sample.Models.ManageViewModels 8 | { 9 | public class TwoFactorAuthenticationViewModel 10 | { 11 | public bool HasAuthenticator { get; set; } 12 | 13 | public int RecoveryCodesLeft { get; set; } 14 | 15 | public bool Is2faEnabled { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AspNetCore.Sample 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | try 18 | { 19 | BuildWebHost(args).Run(); 20 | } 21 | catch(Exception ex) 22 | { 23 | Console.WriteLine(ex); 24 | } 25 | } 26 | 27 | public static IWebHost BuildWebHost(string[] args) => 28 | WebHost.CreateDefaultBuilder(args) 29 | .UseStartup() 30 | .Build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:54380/", 7 | "sslPort": 44314 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "https://localhost:44314/", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AspNetCore.Sample": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | }, 25 | "applicationUrl": "http://localhost:54381/" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/BookService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Extensions.DataValidation; 3 | using AspNetCore.Sample.Models; 4 | 5 | namespace AspNetCore.Sample.Services 6 | { 7 | public class BookService : IBookService 8 | { 9 | public IDataState DataState { get; set; } 10 | 11 | public void Create(CreateBookDto dto) 12 | { 13 | if (string.Equals(dto?.Author, "lemon", StringComparison.Ordinal)) 14 | { 15 | DataState?.Errors?.Add(new DataValidationError("Author", "lemon向阁下问好!")); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/EmailSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspNetCore.Sample.Services 7 | { 8 | // This class is used by the application to send email for account confirmation and password reset. 9 | // For more details see https://go.microsoft.com/fwlink/?LinkID=532713 10 | public class EmailSender : IEmailSender 11 | { 12 | public Task SendEmailAsync(string email, string subject, string message) 13 | { 14 | return Task.CompletedTask; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/IBookService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using AspNetCore.Sample.Models; 6 | 7 | namespace AspNetCore.Sample.Services 8 | { 9 | public interface IBookService 10 | { 11 | void Create(CreateBookDto dto); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Services/IEmailSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspNetCore.Sample.Services 7 | { 8 | public interface IEmailSender 9 | { 10 | Task SendEmailAsync(string email, string subject, string message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Access denied"; 3 | } 4 | 5 |
6 |

ViewData["Title"]

7 |

You do not have access to this resource.

8 |
9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ConfirmEmail.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Confirm email"; 3 | } 4 | 5 |

@ViewData["Title"]

6 |
7 |

8 | Thank you for confirming your email. 9 |

10 |
11 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ForgotPassword.cshtml: -------------------------------------------------------------------------------- 1 | @model ForgotPasswordViewModel 2 | @{ 3 | ViewData["Title"] = "Forgot your password?"; 4 | } 5 | 6 |

@ViewData["Title"]

7 |

Enter your email.

8 |
9 |
10 |
11 |
12 |
13 |
14 | 15 | 16 | 17 |
18 | 19 |
20 |
21 |
22 | 23 | @section Scripts { 24 | @await Html.PartialAsync("_ValidationScriptsPartial") 25 | } 26 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ForgotPasswordConfirmation.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Forgot password confirmation"; 3 | } 4 | 5 |

@ViewData["Title"]

6 |

7 | Please check your email to reset your password. 8 |

9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/Lockout.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Locked out"; 3 | } 4 | 5 |
6 |

@ViewData["Title"]

7 |

This account has been locked out, please try again later.

8 |
9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/LoginWithRecoveryCode.cshtml: -------------------------------------------------------------------------------- 1 | @model LoginWithRecoveryCodeViewModel 2 | @{ 3 | ViewData["Title"] = "Recovery code verification"; 4 | } 5 | 6 |

@ViewData["Title"]

7 |
8 |

9 | You have requested to login with a recovery code. This login will not be remembered until you provide 10 | an authenticator app code at login or disable 2FA and login again. 11 |

12 |
13 |
14 |
15 |
16 |
17 | 18 | 19 | 20 |
21 | 22 |
23 |
24 |
25 | 26 | @section Scripts { 27 | @await Html.PartialAsync("_ValidationScriptsPartial") 28 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/ResetPasswordConfirmation.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Reset password confirmation"; 3 | } 4 | 5 |

@ViewData["Title"]

6 |

7 | Your password has been reset. Please click here to log in. 8 |

9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Account/SignedOut.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Signed out"; 3 | } 4 | 5 |

@ViewData["Title"]

6 |

7 | You have successfully signed out. 8 |

9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Home/About.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "About"; 3 | } 4 |

@ViewData["Title"]

5 |

@ViewData["Message"]

6 | 7 |

Use this area to provide additional information.

8 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Home/Contact.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Contact"; 3 | } 4 |

@ViewData["Title"]

5 |

@ViewData["Message"]

6 | 7 |
8 | One Microsoft Way
9 | Redmond, WA 98052-6399
10 | P: 11 | 425.555.0100 12 |
13 | 14 |
15 | Support: Support@example.com
16 | Marketing: Marketing@example.com 17 |
18 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/Disable2fa.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Disable two-factor authentication (2FA)"; 3 | ViewData.AddActivePage(ManageNavPages.TwoFactorAuthentication); 4 | } 5 | 6 |

@ViewData["Title"]

7 | 8 | 19 | 20 |
21 |
22 | 23 |
24 |
25 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/GenerateRecoveryCodes.cshtml: -------------------------------------------------------------------------------- 1 | @model GenerateRecoveryCodesViewModel 2 | @{ 3 | ViewData["Title"] = "Recovery codes"; 4 | ViewData.AddActivePage(ManageNavPages.TwoFactorAuthentication); 5 | } 6 | 7 |

@ViewData["Title"]

8 | 17 |
18 |
19 | @for (var row = 0; row < Model.RecoveryCodes.Count(); row += 2) 20 | { 21 | @Model.RecoveryCodes[row] @Model.RecoveryCodes[row + 1]
22 | } 23 |
24 |
-------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/ResetAuthenticator.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Reset authenticator key"; 3 | ViewData.AddActivePage(ManageNavPages.TwoFactorAuthentication); 4 | } 5 | 6 |

@ViewData["Title"]

7 | 17 |
18 |
19 | 20 |
21 |
-------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "/Views/Shared/_Layout.cshtml"; 3 | } 4 | 5 |

Manage your account

6 | 7 |
8 |

Change your account settings

9 |
10 |
11 |
12 | @await Html.PartialAsync("_ManageNav") 13 |
14 |
15 | @RenderBody() 16 |
17 |
18 |
19 | 20 | @section Scripts { 21 | @RenderSection("Scripts", required: false) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_ManageNav.cshtml: -------------------------------------------------------------------------------- 1 | @using AspNetCore.Sample.Views.Manage 2 | @inject SignInManager SignInManager 3 | @{ 4 | var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any(); 5 | } 6 | 7 | 16 | 17 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_StatusMessage.cshtml: -------------------------------------------------------------------------------- 1 | @model string 2 | 3 | @if (!String.IsNullOrEmpty(Model)) 4 | { 5 | var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success"; 6 | 10 | } 11 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Manage/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using AspNetCore.Sample.Views.Manage 2 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application. 22 |

23 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @using AspNetCore.Sample.Models 3 | 4 | @inject SignInManager SignInManager 5 | @inject UserManager UserManager 6 | 7 | @if (SignInManager.IsSignedIn(User)) 8 | { 9 | 19 | } 20 | else 21 | { 22 | 26 | } 27 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @using AspNetCore.Sample 3 | @using AspNetCore.Sample.Models 4 | @using AspNetCore.Sample.Models.AccountViewModels 5 | @using AspNetCore.Sample.Models.ManageViewModels 6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 7 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-AspNetCore.Sample-801AA809-9522-45D6-B05D-BA4E539F156C;Trusted_Connection=True;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "IncludeScopes": false, 7 | "LogLevel": { 8 | "Default": "Warning" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "asp.net", 3 | "private": true, 4 | "dependencies": { 5 | "bootstrap": "3.3.7", 6 | "jquery": "2.2.0", 7 | "jquery-validation": "1.14.0", 8 | "jquery-validation-unobtrusive": "3.2.6" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/bundleconfig.json: -------------------------------------------------------------------------------- 1 | // Configure bundling and minification for the project. 2 | // More info at https://go.microsoft.com/fwlink/?LinkId=808241 3 | [ 4 | { 5 | "outputFileName": "wwwroot/css/site.min.css", 6 | // An array of relative input file paths. Globbing patterns supported 7 | "inputFiles": [ 8 | "wwwroot/css/site.css" 9 | ] 10 | }, 11 | { 12 | "outputFileName": "wwwroot/js/site.min.js", 13 | "inputFiles": [ 14 | "wwwroot/js/site.js" 15 | ], 16 | // Optionally specify minification options 17 | "minify": { 18 | "enabled": true, 19 | "renameLocals": true 20 | }, 21 | // Optionally generate .map file 22 | "sourceMap": false 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Wrapping element */ 7 | /* Set some basic padding to keep content from hitting the edges */ 8 | .body-content { 9 | padding-left: 15px; 10 | padding-right: 15px; 11 | } 12 | 13 | /* Carousel */ 14 | .carousel-caption p { 15 | font-size: 20px; 16 | line-height: 1.4; 17 | } 18 | 19 | /* Make .svg files in the carousel display properly in older browsers */ 20 | .carousel-inner .item img[src$=".svg"] { 21 | width: 100%; 22 | } 23 | 24 | /* QR code generator */ 25 | #qrCode { 26 | margin: 15px; 27 | } 28 | 29 | /* Hide/rearrange for smaller screens */ 30 | @media screen and (max-width: 767px) { 31 | /* Hide captions */ 32 | .carousel-caption { 33 | display: none; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/css/site.min.css: -------------------------------------------------------------------------------- 1 | body{padding-top:50px;padding-bottom:20px}.body-content{padding-left:15px;padding-right:15px}.carousel-caption p{font-size:20px;line-height:1.4}.carousel-inner .item img[src$=".svg"]{width:100%}#qrCode{margin:15px}@media screen and (max-width:767px){.carousel-caption{display:none}} -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/favicon.ico -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Write your JavaScript code. 2 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/js/site.min.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/js/site.min.js -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AspectCore/AspectCore-Framework/97f3eb19d348054de5f9da07e05e920ddbae35e9/extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/bootstrap/dist/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/jquery-validation/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery-validation", 3 | "homepage": "http://jqueryvalidation.org/", 4 | "repository": { 5 | "type": "git", 6 | "url": "git://github.com/jzaefferer/jquery-validation.git" 7 | }, 8 | "authors": [ 9 | "Jörn Zaefferer " 10 | ], 11 | "description": "Form validation made easy", 12 | "main": "dist/jquery.validate.js", 13 | "keywords": [ 14 | "forms", 15 | "validation", 16 | "validate" 17 | ], 18 | "license": "MIT", 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "demo", 25 | "lib" 26 | ], 27 | "dependencies": { 28 | "jquery": ">= 1.7.2" 29 | }, 30 | "version": "1.14.0", 31 | "_release": "1.14.0", 32 | "_resolution": { 33 | "type": "version", 34 | "tag": "1.14.0", 35 | "commit": "c1343fb9823392aa9acbe1c3ffd337b8c92fed48" 36 | }, 37 | "_source": "git://github.com/jzaefferer/jquery-validation.git", 38 | "_target": ">=1.8", 39 | "_originalSource": "jquery-validation" 40 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.AspNetCore.Sample/wwwroot/lib/jquery/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "main": "dist/jquery.js", 4 | "license": "MIT", 5 | "ignore": [ 6 | "package.json" 7 | ], 8 | "keywords": [ 9 | "jquery", 10 | "javascript", 11 | "browser", 12 | "library" 13 | ], 14 | "homepage": "https://github.com/jquery/jquery-dist", 15 | "version": "2.2.0", 16 | "_release": "2.2.0", 17 | "_resolution": { 18 | "type": "version", 19 | "tag": "2.2.0", 20 | "commit": "6fc01e29bdad0964f62ef56d01297039cdcadbe5" 21 | }, 22 | "_source": "git://github.com/jquery/jquery-dist.git", 23 | "_target": "2.2.0", 24 | "_originalSource": "jquery" 25 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.Sample/AspectCore.Extensions.Autofac.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.Sample/MethodExecuteLoggerInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using AspectCore.DynamicProxy; 7 | 8 | namespace AspectCore.Extensions.Autofac.Sample 9 | { 10 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor 11 | { 12 | public async override Task Invoke(AspectContext context, AspectDelegate next) 13 | { 14 | Stopwatch stopwatch = Stopwatch.StartNew(); 15 | await next(context); 16 | stopwatch.Stop(); 17 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms", 18 | context.ServiceMethod.DeclaringType.Namespace, 19 | context.ServiceMethod.DeclaringType.Name, 20 | context.ServiceMethod.Name, 21 | context.ServiceMethod.DeclaringType.Assembly.GetName().Name, 22 | stopwatch.ElapsedMilliseconds 23 | ); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/AspectCore.Extensions.Autofac.WebSample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/DynamicProxy/MethodExecuteLoggerInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using AspectCore.DynamicProxy; 7 | 8 | namespace AspectCore.Extensions.Autofac.WebSample 9 | { 10 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor 11 | { 12 | public async override Task Invoke(AspectContext context, AspectDelegate next) 13 | { 14 | Stopwatch stopwatch = Stopwatch.StartNew(); 15 | await next(context); 16 | stopwatch.Stop(); 17 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms", 18 | context.ServiceMethod.DeclaringType.Namespace, 19 | context.ServiceMethod.DeclaringType.Name, 20 | context.ServiceMethod.Name, 21 | context.ServiceMethod.DeclaringType.Assembly.GetName().Name, 22 | stopwatch.ElapsedMilliseconds 23 | ); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AspectCore.Extensions.Autofac.WebSample 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .UseKestrel() 24 | .Build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:16954/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AspectCore.Extensions.Autofac.WebSample": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:16955/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/Services/IValuesService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Extensions.Autofac.WebSample 7 | { 8 | public interface IValuesService 9 | { 10 | IEnumerable GetAll(); 11 | } 12 | 13 | public class ValuesService : IValuesService 14 | { 15 | public IEnumerable GetAll() 16 | { 17 | return new string[] { "value", "value" }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.Autofac.WebSample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.ConsoleSample/AspectCore.Extensions.DependencyInjection.ConsoleSample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/AspectCore.Extensions.DependencyInjection.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Controllers/ControllerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace AspectCore.Extensions.DependencyInjection.Sample.Controllers 8 | { 9 | public abstract class ControllerBase : Controller 10 | { 11 | public virtual IActionResult ApiResult(Func func) 12 | { 13 | return func(); 14 | } 15 | 16 | public virtual IEnumerable ApiResult(Func> func) 17 | { 18 | return func(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/DynamicProxy/MethodExecuteLoggerInterceptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading.Tasks; 4 | using AspectCore.DynamicProxy; 5 | using AspectCore.Injector; 6 | using Microsoft.Extensions.Logging; 7 | 8 | namespace AspectCore.Extensions.DependencyInjection.Sample.DynamicProxy 9 | { 10 | public class MethodExecuteLoggerInterceptor : AbstractInterceptor 11 | { 12 | public async override Task Invoke(AspectContext context, AspectDelegate next) 13 | { 14 | Stopwatch stopwatch = Stopwatch.StartNew(); 15 | await next(context); 16 | stopwatch.Stop(); 17 | Console.WriteLine("Executed method {0}.{1}.{2} ({3}) in {4}ms", 18 | context.ServiceMethod.DeclaringType.Namespace, 19 | context.ServiceMethod.DeclaringType.Name, 20 | context.ServiceMethod.Name, 21 | context.ServiceMethod.DeclaringType.Assembly.GetName().Name, 22 | stopwatch.ElapsedMilliseconds 23 | ); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace AspectCore.Extensions.DependencyInjection.Sample 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .ConfigureLogging(b => b.ClearProviders()) 24 | .Build(); 25 | } 26 | } -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:3980/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/values", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "AspectCore.Extensions.DependencyInjection.Sample": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/values", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:3981/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/Services/IValuesService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Extensions.DependencyInjection.Sample.Services 7 | { 8 | public interface IValuesService 9 | { 10 | IEnumerable GetAll(); 11 | } 12 | 13 | public class ValuesService : IValuesService 14 | { 15 | public IEnumerable GetAll() 16 | { 17 | return new string[] { "value", "value" }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /extras/sample/AspectCore.Extensions.DependencyInjection.Sample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.AspNetCore/Extensions/AspectContextExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace AspectCore.DynamicProxy 6 | { 7 | public static class AspectContextExtensions 8 | { 9 | public static HttpContext GetHttpContext(this AspectContext aspectContext) 10 | { 11 | if (aspectContext == null) 12 | { 13 | throw new ArgumentNullException(nameof(aspectContext)); 14 | } 15 | var httpContextAccessor = aspectContext.ServiceProvider.GetService(); 16 | return httpContextAccessor?.HttpContext; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.AspNetCore/Extensions/ConfigurationExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Configuration; 3 | 4 | namespace AspectCore.Extensions.AspNetCore 5 | { 6 | public static class ConfigurationExtensions 7 | { 8 | public static IAspectConfiguration AddMethodExecuteLogging(this IAspectConfiguration configuration, params AspectPredicate[] predicates) 9 | { 10 | if (configuration == null) 11 | { 12 | throw new ArgumentNullException(nameof(configuration)); 13 | } 14 | configuration.Interceptors.AddTyped(predicates); 15 | return configuration; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.AspNetCore/Filters/ModelStateAdapterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.Filters; 2 | 3 | namespace AspectCore.Extensions.AspNetCore.Filters 4 | { 5 | public class ModelStateAdapterAttribute : ActionFilterAttribute 6 | { 7 | public override void OnActionExecuting(ActionExecutingContext context) 8 | { 9 | context.HttpContext.Items["modelstate-aspectcore"] = context.ModelState; 10 | base.OnActionExecuting(context); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.AspNetCore/Http/ExecutionContextHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading; 5 | 6 | namespace AspectCore.Extensions.AspNetCore.Http 7 | { 8 | public static class ExecutionContextHelper 9 | { 10 | public static ExecutionContext Current { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Autofac/AspectCore.Extensions.Autofac.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Interceptor and dynamicProxy support for Autofac via AspectCore Framework. 8 | AspectCore.Extensions.Autofac 9 | net45;netstandard1.6 10 | AspectCore.Extensions.Autofac 11 | AspectCore.Extensions.Autofac 12 | DynamicProxy;Aop;Autofac;AspectCore 13 | Interceptor and dynamicProxy support for Autofac via AspectCore Framework. 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Autofac/AutofacScopeResolverFactory.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.DynamicProxy; 2 | using AspectCore.Injector; 3 | using Autofac; 4 | 5 | namespace AspectCore.Extensions.Autofac 6 | { 7 | [NonAspect] 8 | internal class AutofacScopeResolverFactory : IScopeResolverFactory 9 | { 10 | private readonly ILifetimeScope _lifetimeScope; 11 | 12 | public AutofacScopeResolverFactory(ILifetimeScope lifetimeScope) 13 | { 14 | this._lifetimeScope = lifetimeScope; 15 | } 16 | 17 | public IServiceResolver CreateScope() 18 | { 19 | return new AutofacServiceResolver(_lifetimeScope.BeginLifetimeScope()); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Autofac/AutofacServiceResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | using AspectCore.Injector; 4 | using Autofac; 5 | 6 | namespace AspectCore.Extensions.Autofac 7 | { 8 | [NonAspect] 9 | internal class AutofacServiceResolver : IServiceResolver 10 | { 11 | private readonly IComponentContext _componentContext; 12 | 13 | public AutofacServiceResolver(IComponentContext componentContext) 14 | { 15 | _componentContext = componentContext; 16 | } 17 | 18 | public void Dispose() 19 | { 20 | var d = _componentContext as IDisposable; 21 | d?.Dispose(); 22 | } 23 | 24 | public object GetService(Type serviceType) 25 | { 26 | return _componentContext.ResolveOptional(serviceType); 27 | } 28 | 29 | public object Resolve(Type serviceType) 30 | { 31 | return _componentContext.ResolveOptional(serviceType); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Autofac/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore.Container.Autofac")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("05c1db04-90da-4d5d-a2a0-655dcc14e1f8")] 20 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/AspectCoreServiceProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.DynamicProxy; 3 | using AspectCore.Injector; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace AspectCore.Extensions.DependencyInjection 7 | { 8 | [NonAspect] 9 | public class AspectCoreServiceProviderFactory : IServiceProviderFactory 10 | { 11 | public IServiceContainer CreateBuilder(IServiceCollection services) 12 | { 13 | return services.ToServiceContainer(); 14 | } 15 | 16 | public IServiceProvider CreateServiceProvider(IServiceContainer containerBuilder) 17 | { 18 | return containerBuilder.Build(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/DynamicProxyServiceProviderFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace AspectCore.Extensions.DependencyInjection 5 | { 6 | public class DynamicProxyServiceProviderFactory : IServiceProviderFactory 7 | { 8 | public IServiceCollection CreateBuilder(IServiceCollection services) 9 | { 10 | return services; 11 | } 12 | 13 | public IServiceProvider CreateServiceProvider(IServiceCollection containerBuilder) 14 | { 15 | return containerBuilder.BuildAspectCoreServiceProvider(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/MsdiScopeResolverFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Injector; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace AspectCore.Extensions.DependencyInjection 6 | { 7 | internal class MsdiScopeResolverFactory : IScopeResolverFactory 8 | { 9 | private readonly IServiceProvider _serviceProvider; 10 | 11 | public MsdiScopeResolverFactory(IServiceProvider serviceProvider) 12 | { 13 | _serviceProvider = serviceProvider; 14 | } 15 | 16 | public IServiceResolver CreateScope() 17 | { 18 | return new MsdiServiceResolver(_serviceProvider.CreateScope().ServiceProvider); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/MsdiServiceResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Injector; 3 | 4 | namespace AspectCore.Extensions.DependencyInjection 5 | { 6 | internal class MsdiServiceResolver : IServiceResolver 7 | { 8 | private readonly IServiceProvider _serviceProvider; 9 | public MsdiServiceResolver(IServiceProvider serviceProvider) 10 | { 11 | _serviceProvider = serviceProvider; 12 | } 13 | 14 | public void Dispose() 15 | { 16 | var d = _serviceProvider as IDisposable; 17 | d?.Dispose(); 18 | } 19 | 20 | public object GetService(Type serviceType) 21 | { 22 | return _serviceProvider.GetService(serviceType); 23 | } 24 | 25 | public object Resolve(Type serviceType) 26 | { 27 | return _serviceProvider.GetService(serviceType); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore Framework")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("00642272-6be8-430c-93d5-db63fec23184")] 20 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/ServiceScope.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Injector; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace AspectCore.Extensions.DependencyInjection 6 | { 7 | internal class ServiceScope : IServiceScope 8 | { 9 | private readonly IServiceResolver _serviceResolver; 10 | public IServiceProvider ServiceProvider => _serviceResolver; 11 | 12 | public ServiceScope(IServiceResolver serviceResolver) 13 | { 14 | _serviceResolver = serviceResolver; 15 | } 16 | 17 | public void Dispose() 18 | { 19 | _serviceResolver.Dispose(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/ServiceScopeFactory.cs: -------------------------------------------------------------------------------- 1 | using AspectCore.Injector; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace AspectCore.Extensions.DependencyInjection 5 | { 6 | internal class ServiceScopeFactory : IServiceScopeFactory 7 | { 8 | private readonly IServiceResolver _serviceResolver; 9 | 10 | public ServiceScopeFactory(IServiceResolver serviceResolver) 11 | { 12 | _serviceResolver = serviceResolver; 13 | } 14 | 15 | public IServiceScope CreateScope() 16 | { 17 | return new ServiceScope(_serviceResolver.CreateScope()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.DependencyInjection/SupportRequiredService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Injector; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace AspectCore.Extensions.DependencyInjection 6 | { 7 | internal class SupportRequiredService : ISupportRequiredService 8 | { 9 | private readonly IServiceResolver _serviceResolver; 10 | 11 | public SupportRequiredService(IServiceResolver serviceResolver) 12 | { 13 | _serviceResolver = serviceResolver; 14 | } 15 | 16 | public object GetRequiredService(Type serviceType) 17 | { 18 | if (serviceType == null) 19 | { 20 | throw new ArgumentNullException(nameof(serviceType)); 21 | } 22 | return _serviceResolver.ResolveRequired(serviceType); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Hosting/AspectCore.Extensions.Hosting.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Windsor/CompatibleCollectionResolver.cs: -------------------------------------------------------------------------------- 1 | using Castle.Core; 2 | using Castle.MicroKernel; 3 | using Castle.MicroKernel.Context; 4 | using Castle.MicroKernel.Resolvers.SpecializedResolvers; 5 | 6 | namespace AspectCore.Extensions.Windsor 7 | { 8 | public class CompatibleCollectionResolver : CollectionResolver 9 | { 10 | public CompatibleCollectionResolver(IKernel kernel) 11 | : base(kernel, allowEmptyCollections: true) 12 | { 13 | } 14 | 15 | public override bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, 16 | DependencyModel dependency) 17 | { 18 | if (kernel.HasComponent(dependency.TargetItemType)) 19 | { 20 | return false; 21 | } 22 | 23 | return base.CanResolve(context, contextHandlerResolver, model, dependency); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /extras/src/AspectCore.Extensions.Windsor/WindsorAspectBuilderFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using AspectCore.DynamicProxy; 3 | 4 | namespace AspectCore.Extensions.Windsor 5 | { 6 | [NonAspect] 7 | internal class WindsorAspectBuilderFactory : IAspectBuilderFactory 8 | { 9 | private readonly IAspectBuilderFactory _aspectBuilderFactory; 10 | private readonly AspectDelegate _complete; 11 | 12 | public WindsorAspectBuilderFactory(IAspectBuilderFactory aspectBuilderFactory, AspectDelegate complete) 13 | { 14 | _aspectBuilderFactory = aspectBuilderFactory; 15 | _complete = complete; 16 | } 17 | 18 | public IAspectBuilder Create(AspectContext context) 19 | { 20 | var builder = _aspectBuilderFactory.Create(context); 21 | return new AspectBuilder(_complete, builder.Delegates.ToList()); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/Fakes/Controller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Extensions.Test.Fakes 7 | { 8 | public class Controller : IController 9 | { 10 | public IService Service { get; } 11 | 12 | public Controller(IService service) 13 | { 14 | Service = service; 15 | } 16 | 17 | public Model Execute() 18 | { 19 | return Service.Get(100); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/Fakes/IController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Extensions.Test.Fakes 7 | { 8 | [CacheInterceptor] 9 | public interface IController 10 | { 11 | IService Service { get; } 12 | Model Execute(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/Fakes/IService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Extensions.Test.Fakes 7 | { 8 | public interface IService 9 | { 10 | [CacheInterceptor] 11 | Model Get(int id); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/Fakes/Model.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace AspectCore.Extensions.Test.Fakes 7 | { 8 | public class Model 9 | { 10 | public int Id { get; set; } 11 | 12 | public Guid Version { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/Fakes/Service.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AspectCore.Extensions.Test.Fakes 4 | { 5 | public class Service : IService 6 | { 7 | public virtual Model Get(int id) 8 | { 9 | return new Model { Id = id, Version = Guid.NewGuid() }; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore.Container.Autofac.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("42599bc2-6584-4ebe-ac03-743d4958a7c3")] 20 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Autofac.Test/SpecificationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Autofac; 3 | using Autofac.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.DependencyInjection.Specification; 6 | 7 | namespace AspectCore.Extensions.Autofac.Test 8 | { 9 | public class SpecificationTests : DependencyInjectionSpecificationTests 10 | { 11 | protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) 12 | { 13 | var builder = new ContainerBuilder(); 14 | builder.Populate(serviceCollection); 15 | return new AutofacServiceProvider(builder.Build()); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.DependencyInjection.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore.Container.DependencyInjection.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("a8b2b7ad-f5cd-4fb7-b0cf-a35a6c33aea7")] 20 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.DependencyInjection.Test/SpecificationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Microsoft.Extensions.DependencyInjection.Specification; 4 | 5 | namespace AspectCore.Extensions.DependencyInjection.Test 6 | { 7 | //public class SpecificationTests : DependencyInjectionSpecificationTests 8 | //{ 9 | // protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) 10 | // { 11 | // serviceCollection.AddAspectCore(option => 12 | // { 13 | // option.InterceptorFactories.AddDelegate((ctx, next) => next(ctx)); 14 | // option.InterceptorFactories.AddDelegate(next => ctx => next(ctx)); 15 | // }); 16 | // return serviceCollection.BuildAspectCoreServiceProvider(); 17 | // } 18 | //} 19 | } 20 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.DependencyInjection.Test/UseMicrosoftDISpecificationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Microsoft.Extensions.DependencyInjection.Specification; 5 | 6 | namespace AspectCore.Extensions.DependencyInjection.Test 7 | { 8 | public class UseMicrosoftDISpecificationTests : DependencyInjectionSpecificationTests 9 | { 10 | protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) 11 | { 12 | serviceCollection.AddDynamicProxy(config => 13 | { 14 | config.Interceptors.AddDelegate((ctx, next) => next(ctx)); 15 | }); 16 | 17 | return serviceCollection.BuildAspectCoreServiceProvider(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.DependencyInjection.Test/Use_Built_In_ContainerSpecificationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AspectCore.Configuration; 3 | using AspectCore.Injector; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.DependencyInjection.Specification; 6 | 7 | namespace AspectCore.Extensions.DependencyInjection.Test 8 | { 9 | // public class Use_Built_In_ContainerSpecificationTests : DependencyInjectionSpecificationTests 10 | // { 11 | // protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection) 12 | // { 13 | // IServiceContainer container = serviceCollection.ToServiceContainer(); 14 | // 15 | // container.Configuration.Interceptors.AddDelegate((ctx, next) => next(ctx)); 16 | // 17 | // return container.Build(); 18 | // } 19 | // } 20 | } -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Hosting.Tests/AspectCore.Extensions.Hosting.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Hosting.Tests/FakeClasses.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Extensions.Hosting.Tests 6 | { 7 | public interface IService 8 | { 9 | string GetValue(); 10 | } 11 | 12 | public class Service : IService 13 | { 14 | public string GetValue() 15 | { 16 | return "service"; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Windsor.Test/AspectCore.Extensions.Windsor.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Windsor.Test/Fakes/CacheService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AspectCore.Extensions.Windsor.Test.Fakes 5 | { 6 | public class CacheService : ICacheService 7 | { 8 | public Model Get(int id) 9 | { 10 | return new Model { Id = id, Version = Guid.NewGuid() }; 11 | } 12 | 13 | public Task GetAsync(int id) 14 | { 15 | return Task.FromResult(Get(id)); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Windsor.Test/Fakes/Controller.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.Windsor.Test.Fakes 2 | { 3 | public class Controller : IController 4 | { 5 | public ICacheService Service { get; } 6 | 7 | public Controller(ICacheService service) 8 | { 9 | Service = service; 10 | } 11 | 12 | public Model Execute() 13 | { 14 | return Service.Get(100); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Windsor.Test/Fakes/ICacheService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace AspectCore.Extensions.Windsor.Test.Fakes 4 | { 5 | public interface ICacheService 6 | { 7 | [CacheInterceptor] 8 | Model Get(int id); 9 | 10 | [CacheInterceptor] 11 | Task GetAsync(int id); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Windsor.Test/Fakes/IController.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.Windsor.Test.Fakes 2 | { 3 | [CacheInterceptor] 4 | public interface IController 5 | { 6 | ICacheService Service { get; } 7 | Model Execute(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /extras/test/AspectCore.Extensions.Windsor.Test/Fakes/Model.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace AspectCore.Extensions.Windsor.Test.Fakes 5 | { 6 | public class Model 7 | { 8 | public int Id { get; set; } 9 | 10 | public Guid Version { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /reflection/README.md: -------------------------------------------------------------------------------- 1 | 在从零实现AOP的过程中,难免会需要大量反射相关的操作,虽然在.net 4.5+/.net core中反射的性能有了大幅的优化,但为了追求极致性能,自己实现了部分反射的替代方案,包括构造器调用、方法调用、字段读写,属性读写和特性读取。在重构时,把反射扩展操作封装到单独的项目中,以此方便自己和大家使用。[获取AspectCore.Extension.Reflection](https://github.com/dotnetcore/AspectCore-Framework/blob/master/docs/reflection-extensions.md) -------------------------------------------------------------------------------- /reflection/performance/AspectCore.Extensions.Reflection.Benchmark/AspectCore.Extensions.Reflection.Benchmark.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp1.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /reflection/performance/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 | -------------------------------------------------------------------------------- /reflection/performance/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 | -------------------------------------------------------------------------------- /reflection/performance/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 | } -------------------------------------------------------------------------------- /reflection/performance/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 | } -------------------------------------------------------------------------------- /reflection/performance/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 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/CallOptions.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.Reflection 2 | { 3 | public enum CallOptions 4 | { 5 | Call, 6 | Callvirt 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/ConstructorReflector.OpenGeneric.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | 6 | namespace AspectCore.Extensions.Reflection 7 | { 8 | public partial class ConstructorReflector 9 | { 10 | private class OpenGenericConstructorReflector : ConstructorReflector 11 | { 12 | public OpenGenericConstructorReflector(ConstructorInfo constructorInfo) : base(constructorInfo) 13 | { 14 | } 15 | 16 | protected override Func CreateInvoker() => null; 17 | 18 | public override object Invoke(params object[] args) => throw new InvalidOperationException($"Cannot create an instance of {_reflectionInfo.DeclaringType} because Type.ContainsGenericParameters is true."); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Emit/IndexedLocalBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection.Emit; 3 | 4 | namespace AspectCore.Extensions.Reflection.Emit 5 | { 6 | public struct IndexedLocalBuilder 7 | { 8 | public LocalBuilder LocalBuilder { get; } 9 | public Type LocalType { get; } 10 | public int Index { get; } 11 | public int LocalIndex { get; } 12 | 13 | public IndexedLocalBuilder(LocalBuilder localBuilder, int index) 14 | { 15 | LocalBuilder = localBuilder; 16 | LocalType = localBuilder.LocalType; 17 | LocalIndex = localBuilder.LocalIndex; 18 | Index = index; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Factories/ConstructorReflector.Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.Extensions.Reflection 5 | { 6 | public partial class ConstructorReflector 7 | { 8 | internal static ConstructorReflector Create(ConstructorInfo constructorInfo) 9 | { 10 | if (constructorInfo == null) 11 | { 12 | throw new ArgumentNullException(nameof(constructorInfo)); 13 | } 14 | return ReflectorCacheUtils.GetOrAdd(constructorInfo, info => 15 | { 16 | if (info.DeclaringType.GetTypeInfo().ContainsGenericParameters) 17 | { 18 | return new OpenGenericConstructorReflector(info); 19 | } 20 | return new ConstructorReflector(info); 21 | }); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Factories/CustomAttributeReflector.Factory.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace AspectCore.Extensions.Reflection 4 | { 5 | public partial class CustomAttributeReflector 6 | { 7 | internal static CustomAttributeReflector Create(CustomAttributeData customAttributeData) 8 | { 9 | return ReflectorCacheUtils.GetOrAdd(customAttributeData, data => new CustomAttributeReflector(data)); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Factories/FieldReflector.Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.Extensions.Reflection 5 | { 6 | public partial class FieldReflector 7 | { 8 | internal static FieldReflector Create(FieldInfo reflectionInfo) 9 | { 10 | if (reflectionInfo == null) 11 | { 12 | throw new ArgumentNullException(nameof(reflectionInfo)); 13 | } 14 | return ReflectorCacheUtils.GetOrAdd(reflectionInfo, CreateInternal); 15 | 16 | FieldReflector CreateInternal(FieldInfo field) 17 | { 18 | if (field.DeclaringType.GetTypeInfo().ContainsGenericParameters) 19 | { 20 | return new OpenGenericFieldReflector(field); 21 | } 22 | if (field.IsStatic) 23 | { 24 | return new StaticFieldReflector(field); 25 | } 26 | return new FieldReflector(field); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Factories/ParameterReflector.Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace AspectCore.Extensions.Reflection 5 | { 6 | public partial class ParameterReflector 7 | { 8 | internal static ParameterReflector Create(ParameterInfo parameterInfo) 9 | { 10 | if (parameterInfo == null) 11 | { 12 | throw new ArgumentNullException(nameof(parameterInfo)); 13 | } 14 | return ReflectorCacheUtils.GetOrAdd(parameterInfo, info => new ParameterReflector(info)); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Factories/TypeReflector.Factory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | using AspectCore.Extensions.Reflection.Internals; 6 | 7 | namespace AspectCore.Extensions.Reflection 8 | { 9 | public partial class TypeReflector 10 | { 11 | internal static TypeReflector Create(TypeInfo typeInfo) 12 | { 13 | if (typeInfo == null) 14 | { 15 | throw new ArgumentNullException(nameof(typeInfo)); 16 | } 17 | return ReflectorCacheUtils.GetOrAdd(typeInfo, info => new TypeReflector(info)); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/ICustomAttributeReflectorProvider.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.Reflection 2 | { 3 | public interface ICustomAttributeReflectorProvider 4 | { 5 | CustomAttributeReflector[] CustomAttributeReflectors { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/IParameterReflectorProvider.cs: -------------------------------------------------------------------------------- 1 | namespace AspectCore.Extensions.Reflection 2 | { 3 | public interface IParameterReflectorProvider 4 | { 5 | ParameterReflector[] ParameterReflectors { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Internals/ConstantsUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Threading.Tasks; 6 | 7 | namespace AspectCore.Extensions.Reflection.Internals 8 | { 9 | internal static class MethodInfoConstant 10 | { 11 | internal static readonly MethodInfo GetTypeFromHandle = InternalExtensions.GetMethod>(handle => Type.GetTypeFromHandle(handle)); 12 | 13 | internal static readonly MethodInfo GetMethodFromHandle = InternalExtensions.GetMethod>((h1, h2) => MethodBase.GetMethodFromHandle(h1, h2)); 14 | 15 | internal static readonly ConstructorInfo ArgumentNullExceptionCtor = typeof(ArgumentNullException).GetTypeInfo().GetConstructor(new Type[] { typeof(string) }); 16 | 17 | internal static readonly ConstructorInfo ObjectCtor = typeof(object).GetTypeInfo().DeclaredConstructors.Single(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/MemberReflector.CustomAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | 6 | namespace AspectCore.Extensions.Reflection 7 | { 8 | public abstract partial class MemberReflector : ICustomAttributeReflectorProvider where TMemberInfo : MemberInfo 9 | { 10 | private readonly CustomAttributeReflector[] _customAttributeReflectors; 11 | 12 | public CustomAttributeReflector[] CustomAttributeReflectors => _customAttributeReflectors; 13 | } 14 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/MemberReflector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Linq; 4 | 5 | namespace AspectCore.Extensions.Reflection 6 | { 7 | public abstract partial class MemberReflector where TMemberInfo : MemberInfo 8 | { 9 | protected TMemberInfo _reflectionInfo; 10 | 11 | public virtual string Name => _reflectionInfo.Name; 12 | 13 | protected MemberReflector(TMemberInfo reflectionInfo) 14 | { 15 | _reflectionInfo = reflectionInfo ?? throw new ArgumentNullException(nameof(reflectionInfo)); 16 | _customAttributeReflectors = _reflectionInfo.CustomAttributes.Select(data => CustomAttributeReflector.Create(data)).ToArray(); 17 | } 18 | 19 | public override string ToString() => $"{_reflectionInfo.MemberType} : {_reflectionInfo} DeclaringType : {_reflectionInfo.DeclaringType}"; 20 | 21 | public TMemberInfo GetMemberInfo() => _reflectionInfo; 22 | 23 | public virtual string DisplayName => _reflectionInfo.Name; 24 | } 25 | } -------------------------------------------------------------------------------- /reflection/src/AspectCore.Extensions.Reflection/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore Framework")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("cab96f50-44e1-4d8e-9149-ddcba1fbe493")] 20 | -------------------------------------------------------------------------------- /reflection/test/AspectCore.Extensions.Reflection.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AspectCore.Extensions.Reflection.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("e0f82471-75e5-4d48-bc00-d6b829a45846")] 20 | --------------------------------------------------------------------------------