├── .editorconfig ├── .git-blame-ignore-revs ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── build.yml │ ├── ci.yml │ ├── dotnet-format.yml │ ├── pre-commit.yml │ └── publish.yml ├── .gitignore ├── .mailmap ├── .markdownlint.json ├── .pre-commit-config.yaml ├── .vscode ├── extensions.json ├── settings.json └── tasks.json ├── Autofac.sln ├── Autofac.sln.DotSettings ├── Autofac.snk ├── Directory.Build.props ├── LICENSE ├── NuGet.Config ├── README.md ├── bench ├── Autofac.BenchmarkProfiling │ ├── Autofac.BenchmarkProfiling.csproj │ ├── Program.cs │ └── Properties │ │ └── launchSettings.json └── Autofac.Benchmarks │ ├── Autofac.Benchmarks.csproj │ ├── BenchmarkConfig.cs │ ├── BenchmarkSet.cs │ ├── ChildScopeResolveBenchmark.cs │ ├── ConcurrencyBenchmark.cs │ ├── ConcurrencyNestedScopeBenchmark.cs │ ├── Decorators │ ├── DecoratorBenchmarkBase.cs │ ├── KeyedGenericBenchmark.cs │ ├── KeyedNestedBenchmark.cs │ ├── KeyedSimpleBenchmark.cs │ ├── KeylessGenericBenchmark.cs │ ├── KeylessNestedBenchmark.cs │ ├── KeylessNestedLambdaBenchmark.cs │ ├── KeylessNestedSharedInstanceBenchmark.cs │ ├── KeylessNestedSharedInstanceLambdaBenchmark.cs │ ├── KeylessSimpleBenchmark.cs │ ├── KeylessSimpleLambdaBenchmark.cs │ ├── KeylessSimpleSharedInstanceBenchmark.cs │ ├── KeylessSimpleSharedInstanceLambdaBenchmark.cs │ └── Scenario │ │ ├── Command.cs │ │ ├── CommandHandlerDecoratorOne.cs │ │ ├── CommandHandlerDecoratorTwo.cs │ │ ├── CommandHandlerOne.cs │ │ ├── CommandHandlerTwo.cs │ │ ├── GenericCommandHandlerDecorator.cs │ │ ├── GenericCommandHandlerOne.cs │ │ ├── GenericCommandHandlerTwo.cs │ │ ├── ICommandHandler.cs │ │ └── ICommandHandler`1.cs │ ├── DeepGraphResolveBenchmark.cs │ ├── EnumerableResolveBenchmark.cs │ ├── LambdaResolveBenchmark.cs │ ├── MultiConstructorBenchmark.cs │ ├── OpenGenericBenchmark.cs │ ├── Program.cs │ ├── PropertyInjectionBenchmark.cs │ ├── RequiredPropertyBenchmark.cs │ ├── RootContainerResolveBenchmark.cs │ └── xunit.runner.json ├── build ├── Coverage.runsettings ├── Documentation.proj ├── Documentation.shfbproj ├── Source.ruleset ├── Test.ruleset ├── icon.png └── stylecop.json ├── codecov.yml ├── codegen └── Autofac.CodeGen │ ├── Autofac.CodeGen.csproj │ ├── DelegateRegisterGenerator.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── README.md ├── default.proj ├── global.json ├── src └── Autofac │ ├── Autofac.csproj │ ├── Builder │ ├── BuildCallbackManager.cs │ ├── BuildCallbackService.cs │ ├── BuildCallbackServiceResources.resx │ ├── ConcreteReflectionActivatorData.cs │ ├── ContainerBuildOptions.cs │ ├── DeferredCallback.cs │ ├── DynamicRegistrationStyle.cs │ ├── IConcreteActivatorData.cs │ ├── IHideObjectMembers.cs │ ├── IRegistrationBuilder.cs │ ├── MetadataConfiguration.cs │ ├── MetadataKeys.cs │ ├── ReflectionActivatorData.cs │ ├── RegistrationBuilder.cs │ ├── RegistrationBuilderResources.resx │ ├── RegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle}.cs │ ├── RegistrationData.cs │ ├── RegistrationExtensions.cs │ ├── RegistrationOrderExtensions.cs │ ├── SimpleActivatorData.cs │ ├── SingleRegistrationStyle.cs │ └── StartableManager.cs │ ├── ContainerBuilder.cs │ ├── ContainerBuilderResources.resx │ ├── ContainerExtensions.cs │ ├── Core │ ├── ActivatedEventArgs.cs │ ├── ActivatingEventArgs.cs │ ├── Activators │ │ ├── DefaultPropertySelector.cs │ │ ├── Delegate │ │ │ ├── DelegateActivator.cs │ │ │ └── DelegateActivatorResources.resx │ │ ├── DelegatePropertySelector.cs │ │ ├── IPropertySelector.cs │ │ ├── InstanceActivator.cs │ │ ├── InstanceActivatorResources.resx │ │ ├── ProvidedInstance │ │ │ ├── ProvidedInstanceActivator.cs │ │ │ └── ProvidedInstanceActivatorResources.resx │ │ └── Reflection │ │ │ ├── AutowiringParameter.cs │ │ │ ├── AutowiringPropertyInjector.cs │ │ │ ├── BoundConstructor.cs │ │ │ ├── BoundConstructorResources.resx │ │ │ ├── ConstructorBinder.cs │ │ │ ├── DefaultConstructorFinder.cs │ │ │ ├── DefaultValueParameter.cs │ │ │ ├── IConstructorFinder.cs │ │ │ ├── IConstructorSelector.cs │ │ │ ├── IConstructorSelectorWithEarlyBinding.cs │ │ │ ├── InjectableProperty.cs │ │ │ ├── InjectablePropertyState.cs │ │ │ ├── MatchingSignatureConstructorSelector.cs │ │ │ ├── MatchingSignatureConstructorSelectorResources.resx │ │ │ ├── MostParametersConstructorSelector.cs │ │ │ ├── MostParametersConstructorSelectorResources.resx │ │ │ ├── NoConstructorsFoundException.cs │ │ │ ├── NoConstructorsFoundExceptionResources.resx │ │ │ ├── ReflectionActivator.cs │ │ │ └── ReflectionActivatorResources.resx │ ├── AutoActivateService.cs │ ├── ComponentRegisteredEventArgs.cs │ ├── ComponentRegistrationExtensions.cs │ ├── ConstantParameter.cs │ ├── Container.cs │ ├── ContainerResources.resx │ ├── DependencyResolutionException.cs │ ├── Disposer.cs │ ├── DisposerResources.resx │ ├── IActivatedEventArgs.cs │ ├── IActivatingEventArgs.cs │ ├── IComponentLifetime.cs │ ├── IComponentRegistration.cs │ ├── IComponentRegistry.cs │ ├── IComponentRegistryServices.cs │ ├── IDisposer.cs │ ├── IInstanceActivator.cs │ ├── IModule.cs │ ├── IReflectionCache.cs │ ├── IRegistrationSource.cs │ ├── IServiceWithType.cs │ ├── ISharingLifetimeScope.cs │ ├── ImplicitRegistrationSource.cs │ ├── ImplicitRegistrationSourceResources.resx │ ├── InstanceOwnership.cs │ ├── InstanceSharing.cs │ ├── InternalReflectionCaches.cs │ ├── KeyedService.cs │ ├── Lifetime │ │ ├── CurrentScopeLifetime.cs │ │ ├── LifetimeScope.cs │ │ ├── LifetimeScopeBeginningEventArgs.cs │ │ ├── LifetimeScopeEndingEventArgs.cs │ │ ├── LifetimeScopeResources.resx │ │ ├── MatchingScopeLifetime.cs │ │ ├── MatchingScopeLifetimeResources.resx │ │ ├── MatchingScopeLifetimeTags.cs │ │ └── RootScopeLifetime.cs │ ├── NamedPropertyParameter.cs │ ├── Parameter.cs │ ├── PreparingEventArgs.cs │ ├── ReflectionCacheSet.cs │ ├── ReflectionCacheSetResources.resx │ ├── ReflectionCacheUsage.cs │ ├── Registration │ │ ├── ComponentNotRegisteredException.cs │ │ ├── ComponentNotRegisteredExceptionResources.resx │ │ ├── ComponentPipelineBuildingArgs.cs │ │ ├── ComponentRegistration.cs │ │ ├── ComponentRegistrationExtensions.cs │ │ ├── ComponentRegistrationLifetimeDecorator.cs │ │ ├── ComponentRegistrationResources.resx │ │ ├── ComponentRegistry.cs │ │ ├── ComponentRegistryBuilder.cs │ │ ├── DefaultRegisteredServicesTracker.cs │ │ ├── ExternalComponentRegistration.cs │ │ ├── ExternalRegistryServiceMiddlewareSource.cs │ │ ├── ExternalRegistrySource.cs │ │ ├── IComponentRegistryBuilder.cs │ │ ├── IModuleRegistrar.cs │ │ ├── IPerScopeRegistrationSource.cs │ │ ├── IRegisteredServicesTracker.cs │ │ ├── IServiceMiddlewareSource.cs │ │ ├── IServiceMiddlewareSourceRegistrar.cs │ │ ├── ISourceRegistrar.cs │ │ ├── ModuleRegistrar.cs │ │ ├── ModuleRegistrarData.cs │ │ ├── RegistrationOptions.cs │ │ ├── RegistrationOptionsExtensions.cs │ │ ├── ScopeRestrictedRegisteredServicesTracker.cs │ │ ├── ServiceMiddlewareSourceRegistrar.cs │ │ ├── ServiceRegistrationInfo.cs │ │ ├── ServiceRegistrationInfoResources.resx │ │ ├── ServiceWithTypeMiddlewareSource.cs │ │ └── SourceRegistrar.cs │ ├── RegistrationSourceAddedEventArgs.cs │ ├── ResolvedParameter.cs │ ├── Resolving │ │ ├── ActivatorExtensions.cs │ │ ├── BaseGenericResolveDelegateInvoker.cs │ │ ├── ComponentActivationResources.resx │ │ ├── IDependencyTrackingResolveOperation.cs │ │ ├── IResolveOperation.cs │ │ ├── Middleware │ │ │ ├── ActivatorErrorHandlingMiddleware.cs │ │ │ ├── CircularDependencyDetectorMessages.resx │ │ │ ├── CircularDependencyDetectorMiddleware.cs │ │ │ ├── CoreEventMiddleware.cs │ │ │ ├── DelegateMiddleware.cs │ │ │ ├── DisposalTrackingMiddleware.cs │ │ │ ├── MiddlewareMessages.resx │ │ │ ├── RegistrationPipelineInvokeMiddleware.cs │ │ │ ├── ScopeSelectionMiddleware.cs │ │ │ ├── SharingMiddleware.cs │ │ │ └── StartableMiddleware.cs │ │ ├── Pipeline │ │ │ ├── DefaultResolveRequestContext.cs │ │ │ ├── IResolveMiddleware.cs │ │ │ ├── IResolvePipeline.cs │ │ │ ├── IResolvePipelineBuilder.cs │ │ │ ├── MiddlewareDeclaration.cs │ │ │ ├── MiddlewareInsertionMode.cs │ │ │ ├── PipelineBuilderEnumerator.cs │ │ │ ├── PipelinePhase.cs │ │ │ ├── PipelineType.cs │ │ │ ├── ResolvePipelineBuilder.cs │ │ │ ├── ResolvePipelineBuilderMessages.resx │ │ │ ├── ResolveRequestContext.cs │ │ │ └── ServicePipelines.cs │ │ ├── ResolveEventType.cs │ │ ├── ResolveOperation.cs │ │ ├── ResolveOperationBeginningEventArgs.cs │ │ ├── ResolveOperationEndingEventArgs.cs │ │ ├── ResolveOperationResources.resx │ │ ├── ResolvePipeline.cs │ │ ├── ResolveRequestBeginningEventArgs.cs │ │ ├── ResolveRequestCompletingEventArgs.cs │ │ ├── SegmentedStack.cs │ │ └── SegmentedStackResources.resx │ ├── ScopeIsolatedService.cs │ ├── SelfComponentRegistration.cs │ ├── Service.cs │ ├── ServiceRegistration.cs │ ├── ServiceResources.resx │ ├── TypedService.cs │ └── UniqueService.cs │ ├── Diagnostics │ ├── DefaultDiagnosticTracer.cs │ ├── DiagnosticEventKeys.cs │ ├── DiagnosticSourceExtensions.cs │ ├── DiagnosticTracerBase.cs │ ├── MiddlewareDiagnosticData.cs │ ├── OperationDiagnosticTracerBase.cs │ ├── OperationFailureDiagnosticData.cs │ ├── OperationStartDiagnosticData.cs │ ├── OperationSuccessDiagnosticData.cs │ ├── OperationTraceCompletedArgs.cs │ ├── RequestDiagnosticData.cs │ ├── RequestFailureDiagnosticData.cs │ └── TracerMessages.resx │ ├── Features │ ├── AttributeFilters │ │ ├── KeyFilterAttribute.cs │ │ ├── MetadataFilterAttribute.cs │ │ ├── ParameterFilterAttribute.cs │ │ └── RegistrationExtensions.cs │ ├── Collections │ │ ├── CollectionRegistrationSource.cs │ │ └── CollectionRegistrationSourceResources.resx │ ├── Decorators │ │ ├── DecoratorContext.cs │ │ ├── DecoratorMiddleware.cs │ │ ├── DecoratorService.cs │ │ ├── IDecoratorContext.cs │ │ └── OpenGenericDecoratorMiddlewareSource.cs │ ├── GeneratedFactories │ │ ├── FactoryGenerator.cs │ │ ├── GeneratedFactoryActivatorData.cs │ │ ├── GeneratedFactoryRegistrationExtensions.cs │ │ ├── GeneratedFactoryRegistrationSource.cs │ │ ├── GeneratedFactoryRegistrationSourceResources.resx │ │ └── ParameterMapping.cs │ ├── Indexed │ │ ├── IIndex.cs │ │ └── KeyedServiceIndex.cs │ ├── LazyDependencies │ │ ├── LazyRegistrationSource.cs │ │ ├── LazyRegistrationSourceResources.resx │ │ ├── LazyWithMetadataRegistrationSource.cs │ │ └── LazyWithMetadataRegistrationSourceResources.resx │ ├── LightweightAdapters │ │ ├── LightweightAdapterActivatorData.cs │ │ ├── LightweightAdapterRegistrationExtensions.cs │ │ ├── LightweightAdapterRegistrationSource.cs │ │ └── LightweightAdapterRegistrationSourceResources.resx │ ├── Metadata │ │ ├── MetaRegistrationSource.cs │ │ ├── MetaRegistrationSourceResources.resx │ │ ├── MetadataViewProvider.cs │ │ ├── MetadataViewProviderResources.resx │ │ ├── Meta{T,TMetadata}.cs │ │ ├── Meta{T}.cs │ │ └── StronglyTypedMetaRegistrationSource.cs │ ├── OpenGenerics │ │ ├── OpenGenericDecoratorActivatorData.cs │ │ ├── OpenGenericDecoratorActivatorDataResources.resx │ │ ├── OpenGenericDecoratorRegistrationSource.cs │ │ ├── OpenGenericDecoratorRegistrationSourceResources.resx │ │ ├── OpenGenericDelegateActivatorData.cs │ │ ├── OpenGenericDelegateRegistrationSource.cs │ │ ├── OpenGenericDelegateRegistrationSourceResources.resx │ │ ├── OpenGenericRegistrationExtensions.cs │ │ ├── OpenGenericRegistrationExtensionsResources.resx │ │ ├── OpenGenericRegistrationSource.cs │ │ ├── OpenGenericRegistrationSourceResources.resx │ │ ├── OpenGenericServiceBinder.cs │ │ └── OpenGenericServiceBinderResources.resx │ ├── OwnedInstances │ │ ├── InstancePerOwnedKey.cs │ │ ├── Owned.cs │ │ ├── OwnedInstanceRegistrationSource.cs │ │ └── OwnedInstanceRegistrationSourceResources.resx │ ├── ResolveAnything │ │ ├── AnyConcreteTypeNotAlreadyRegisteredSource.cs │ │ ├── AnyConcreteTypeNotAlreadyRegisteredSourceExtensions.cs │ │ └── AnyConcreteTypeNotAlreadyRegisteredSourceResources.resx │ ├── Scanning │ │ ├── AssemblyExtensions.cs │ │ ├── BaseScanningActivatorData.cs │ │ ├── OpenGenericScanningActivatorData.cs │ │ ├── OpenGenericScanningRegistrationExtensions.cs │ │ ├── ScanningActivatorData.cs │ │ ├── ScanningRegistrationExtensions.cs │ │ └── TypeExtensions.cs │ └── Variance │ │ └── ContravariantRegistrationSource.cs │ ├── IComponentContext.cs │ ├── IContainer.cs │ ├── ILifetimeScope.cs │ ├── IStartable.cs │ ├── Module.cs │ ├── ModuleRegistrationExtensions.cs │ ├── ModuleResources.resx │ ├── NamedParameter.cs │ ├── ParameterExtensions.cs │ ├── PipelineBuilderExtensions.cs │ ├── PositionalParameter.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── PropertyWiringOptions.cs │ ├── RegistrationExtensions.Adapter.cs │ ├── RegistrationExtensions.AssemblyScanning.cs │ ├── RegistrationExtensions.Composite.cs │ ├── RegistrationExtensions.Conditional.cs │ ├── RegistrationExtensions.Decorators.cs │ ├── RegistrationExtensions.EventHandler.cs │ ├── RegistrationExtensions.Generics.cs │ ├── RegistrationExtensions.Keyed.cs │ ├── RegistrationExtensions.Named.cs │ ├── RegistrationExtensions.OpenGenericAssemblyScanning.cs │ ├── RegistrationExtensions.cs │ ├── RegistrationExtensionsResources.resx │ ├── ResolutionExtensions.cs │ ├── ResolutionExtensionsResources.resx │ ├── ResolutionValueExtensions.cs │ ├── ResolveRequest.cs │ ├── ScanningFilterExtensions.cs │ ├── ServiceMiddlewareRegistrationExtensions.cs │ ├── SourceRegistrationExtensions.cs │ ├── TypeExtensions.cs │ ├── TypeExtensionsResources.resx │ ├── TypedParameter.cs │ └── Util │ ├── AssemblyExtensions.cs │ ├── AsyncReleaseAction.cs │ ├── Cache │ ├── ReflectionCacheAssemblyDictionary.cs │ ├── ReflectionCacheDictionary.cs │ ├── ReflectionCacheTupleDictionary.cs │ └── TypeAssemblyReferenceProvider.cs │ ├── Disposable.cs │ ├── Enforce.cs │ ├── EnforceResources.resx │ ├── FallbackDictionary.cs │ ├── FallbackDictionaryResources.resx │ ├── InternalTypeExtensions.cs │ ├── LinkerAttributes.cs │ ├── NullableAttributes.cs │ ├── ReflectionExtensions.cs │ ├── ReflectionExtensionsResources.resx │ ├── ReleaseAction.cs │ ├── SequenceExtensions.cs │ ├── SequenceGenerator.cs │ ├── Traverse.cs │ └── ValidatedNotNullAttribute.cs └── test ├── Autofac.Specification.Test ├── Autofac.Specification.Test.csproj ├── ContainerBuilderTests.cs ├── Diagnostics │ ├── DefaultDiagnosticTracerTests.cs │ └── DiagnosticTracerBaseTests.cs ├── Features │ ├── CircularDependency │ │ ├── A.cs │ │ ├── BC.cs │ │ ├── D.cs │ │ ├── DependsByCtor.cs │ │ ├── DependsByProp.cs │ │ ├── IA.cs │ │ ├── IB.cs │ │ ├── IC.cs │ │ └── ID.cs │ ├── CircularDependencyTests.cs │ ├── CompositeTests.cs │ ├── DecoratorTests.cs │ ├── IndexTests.cs │ ├── MetadataTests.cs │ ├── PropertyInjection │ │ ├── CtorWithValueParameter.cs │ │ ├── HasMixedVisibilityProperties.cs │ │ ├── HasProtectedSetterWithDefaultValue.cs │ │ ├── HasPublicSetter.cs │ │ ├── HasPublicSetterDerived.cs │ │ ├── HasPublicSetterWithDefaultValue.cs │ │ ├── HasStaticSetter.cs │ │ ├── HasWriteOnlyProperty.cs │ │ ├── InjectAttribute.cs │ │ └── InjectAttributePropertySelector.cs │ ├── PropertyInjectionTests.cs │ ├── RequiredPropertyTests.cs │ └── StartableTests.cs ├── Lifetime │ ├── AsyncDisposeProvidedInstanceTests.cs │ ├── DisposalTests.cs │ ├── ExternallyOwnedTests.cs │ ├── InstancePerDependencyTests.cs │ ├── InstancePerLifetimeScopeTests.cs │ ├── InstancePerMatchingLifetimeScopeTests.cs │ ├── InstancePerOwnedTests.cs │ ├── LifetimeEventTests.cs │ ├── NestedScopeTests.cs │ ├── ProvidedInstanceTests.cs │ └── SingleInstanceTests.cs ├── LoadContextScopeTests.cs ├── ParameterFilterTests.cs ├── Registration │ ├── Adapters │ │ ├── AnotherCommand.cs │ │ ├── Command.cs │ │ ├── IToolbarButton.cs │ │ └── ToolbarButton.cs │ ├── AssemblyScanningPerformanceTests.cs │ ├── AssemblyScanningTests.cs │ ├── InstanceRegistrationTests.cs │ ├── KeyedRegistrationTests.cs │ ├── LambdaGenericOverloadRegistrationTests.cs │ ├── LambdaRegistrationTests.cs │ ├── ModuleRegistrationTests.cs │ ├── NestedScopeRegistrationTests.cs │ ├── OpenGenericDelegateTests.cs │ ├── OpenGenericTests.cs │ ├── OpenGenericWithMultipleInterfacesTests.cs │ ├── OrderingTests.cs │ ├── ParameterTests.cs │ ├── PropertyDictionaryTests.cs │ ├── RegistrationOnlyIfTests.cs │ └── TypeRegistrationTests.cs ├── Resolution │ ├── ComplexGraphTests.cs │ ├── ConstructorFinderTests.cs │ ├── ConstructorSelectorTests.cs │ └── Graph1 │ │ ├── A1.cs │ │ ├── B1.cs │ │ ├── C1.cs │ │ ├── CD1.cs │ │ ├── E1.cs │ │ ├── F1.cs │ │ ├── GenericConstraints │ │ ├── A.cs │ │ ├── ClassWithParameterlessButNotPublicConstructor.cs │ │ ├── IA.cs │ │ ├── IB.cs │ │ ├── Required.cs │ │ └── Unrelated.cs │ │ ├── IC1.cs │ │ └── ID1.cs └── Util │ ├── AsyncOnlyDisposeTracker.cs │ └── DisposeTracker.cs ├── Autofac.Test.CodeGen ├── Autofac.Test.CodeGen.csproj ├── DelegateRegisterGeneratorTests.cs ├── Helpers │ ├── CompilationVerifier.cs │ └── ModuleInitializer.cs ├── README.md └── Snapshots │ ├── .gitignore │ ├── DelegateRegisterGeneratorTests.VerifyGeneratedCode#00.verified.cs │ └── DelegateRegisterGeneratorTests.VerifyGeneratedCode#01.verified.cs ├── Autofac.Test.Compilation ├── Autofac.Test.Compilation.csproj ├── AutofacCompile.cs ├── BaseClass.cs ├── DerivedClass.cs ├── NullableReferenceTests.cs └── SimpleReferenceType.cs ├── Autofac.Test.Scenarios.LoadContext ├── Autofac.Test.Scenarios.LoadContext.csproj ├── LifetimeScopeEndingModule.cs ├── OnActivatedModule.cs └── Service1.cs ├── Autofac.Test.Scenarios.ScannedAssembly ├── A2Component.cs ├── AComponent.cs ├── ADisposable.cs ├── AModule.cs ├── Autofac.Test.Scenarios.ScannedAssembly.csproj ├── BComponent.cs ├── BModule.cs ├── CloseCommand.cs ├── CommandBase.cs ├── DeleteCommand.cs ├── DeleteCommandData.cs ├── DeleteOpenGenericCommand.cs ├── HasDeferredEnumerable.cs ├── HasNestedFactoryDelegate.cs ├── IAService.cs ├── IBService.cs ├── ICloseCommand.cs ├── ICommand.cs ├── IHaveDeferredEnumerable.cs ├── IOpenGenericAService.cs ├── IOpenGenericBService.cs ├── InternalComponent.cs ├── Message.cs ├── MetadataAttributeScanningScenario │ ├── DuplicatedNameAttribute.cs │ ├── IHaveName.cs │ ├── NameAttribute.cs │ ├── OpenGenericScannedComponentWithMultipleNames.cs │ ├── OpenGenericScannedComponentWithName.cs │ └── ScannedComponentWithName.cs ├── ModuleBase.cs ├── NestedComponent.cs ├── OpenGenericA2Component.cs ├── OpenGenericAComponent.cs ├── Properties │ └── AssemblyInfo.cs ├── RedoCommandData.cs ├── RedoOpenGenericCommand.cs ├── SaveCommand.cs ├── SaveCommandData.cs ├── StringMessage.cs ├── UndoCommandData.cs └── UndoRedoCommand.cs ├── Autofac.Test ├── ActivatorPipelineExtensions.cs ├── Assertions.cs ├── Autofac.Test.csproj ├── Builder │ ├── DeferredCallbackTests.cs │ ├── DelegateRegistrationBuilderTests.cs │ ├── PropertyInjectionTests.cs │ ├── ProvidedInstanceRegistrationBuilderTests.cs │ ├── ReflectiveRegistrationBuilderTests.cs │ └── RegistrationBuilderTests.cs ├── CircularDependencyTests.cs ├── Concurrency │ └── ConcurrencyTests.cs ├── ContainerBuilderTests.cs ├── Core │ ├── Activators │ │ ├── Delegate │ │ │ └── DelegateActivatorTests.cs │ │ ├── ProvidedInstance │ │ │ └── ProvidedInstanceActivatorTests.cs │ │ └── Reflection │ │ │ ├── ConstructorBinderTests.cs │ │ │ ├── DefaultConstructorFinderTests.cs │ │ │ ├── DefaultValueParameterTests.cs │ │ │ ├── MatchingSignatureConstructorSelectorTests.cs │ │ │ ├── MostParametersConstructorSelectorTests.cs │ │ │ ├── RecordTests.cs │ │ │ └── ReflectionActivatorTests.cs │ ├── ComponentRegisteredEventArgsTests.cs │ ├── ComponentRegistrationExtensionsTests.cs │ ├── ComponentRegistrationTests.cs │ ├── ContainerTests.cs │ ├── DefaultPropertySelectorTests.cs │ ├── DelegatePropertySelectorTests.cs │ ├── DependencyResolutionExceptionTests.cs │ ├── DisposerTests.cs │ ├── ImplicitRegistrationSourceTests.cs │ ├── KeyedServiceTests.cs │ ├── Lifetime │ │ ├── LifetimeScopeTests.cs │ │ └── MatchingScopeLifetimeTests.cs │ ├── NamedPropertyParameterTests.cs │ ├── Pipeline │ │ └── PipelineBuilderTests.cs │ ├── PreserveExistingDefaultsTests.cs │ ├── PropertyInjectionInitOnlyTests.cs │ ├── ReflectionCacheSetTests.cs │ ├── Registration │ │ ├── ComponentRegistrationLifetimeDecoratorTests.cs │ │ ├── ComponentRegistryTests.cs │ │ ├── ModuleRegistrarTests.cs │ │ ├── ScopeRestrictedRegisteredServicesTrackerTests.cs │ │ └── SourceRegistrarTests.cs │ ├── ResolvedParameterTests.cs │ ├── Resolving │ │ ├── CircularDependencyDetectorTests.cs │ │ ├── Middleware │ │ │ └── CircularDependencyMiddlewareTests.cs │ │ ├── ResolveOperationTests.cs │ │ └── SegmentedStackTests.cs │ └── TypedServiceTests.cs ├── Diagnostics │ ├── DiagnosticSourceExtensionsTests.cs │ ├── DiagnosticTracerBaseTests.cs │ └── OperationDiagnosticTracerBaseTests.cs ├── Factory.cs ├── Features │ ├── AttributeFilters │ │ └── WithAttributeFilterTestFixture.cs │ ├── Collections │ │ ├── CollectionOrderingTests.cs │ │ └── CollectionRegistrationSourceTests.cs │ ├── Decorators │ │ ├── DecoratorContextTests.cs │ │ ├── DecoratorMiddlewareTests.cs │ │ ├── DecoratorServiceTests.cs │ │ ├── DecoratorTests.cs │ │ ├── OpenGenericDecoratorTests.cs │ │ └── RegistrationExtensionsTests.cs │ ├── GeneratedFactories │ │ └── GeneratedFactoriesTests.cs │ ├── Indexed │ │ └── KeyedServiceIndexTests.cs │ ├── LazyDependencies │ │ ├── LazyRegistrationSourceTests.cs │ │ ├── LazyWithMetadata_WhenMetadataIsSupplied.cs │ │ └── LazyWithMetadata_WhenNoMatchingMetadataIsSupplied.cs │ ├── LightweightAdapters │ │ ├── LightweightAdapterRegistrationExtensionsTests.cs │ │ └── LightweightAdapterRegistrationSourceTests.cs │ ├── Metadata │ │ ├── MetaRegistrationSourceTests.cs │ │ ├── StronglyTypedMeta_WhenMetadataIsSupplied.cs │ │ ├── StronglyTypedMeta_WhenNoMatchingMetadataIsSupplied.cs │ │ └── TestTypes │ │ │ ├── IMyMetaInterface.cs │ │ │ ├── MyMeta.cs │ │ │ ├── MyMetaWithDefault.cs │ │ │ ├── MyMetaWithDictionary.cs │ │ │ ├── MyMetaWithInvalidConstructor.cs │ │ │ └── MyMetaWithReadOnlyProperty.cs │ ├── OpenGenerics │ │ ├── ComplexGenericScenarios │ │ │ ├── CompanyA │ │ │ │ ├── CompositeValidator{T}.cs │ │ │ │ └── IValidator{T}.cs │ │ │ ├── CompanyB │ │ │ │ ├── CompositeValidator{T}.cs │ │ │ │ └── IValidatorSomeOtherName{T}.cs │ │ │ └── FluentValidation │ │ │ │ ├── AbstractValidator{T}.cs │ │ │ │ └── IValidator{T}.cs │ │ ├── ComplexGenericsTests.cs │ │ ├── GenericsForNullableScenarioTests.cs │ │ ├── OpenGenericDecoratorTests.cs │ │ ├── OpenGenericRegistrationExtensionsTests.cs │ │ └── OpenGenericRegistrationSourceTests.cs │ ├── OwnedInstances │ │ ├── InstancePerOwnedKeyTests.cs │ │ ├── OwnedInstanceRegistrationSourceTests.cs │ │ └── OwnedTests.cs │ ├── ResolveAnything │ │ └── ResolveAnythingTests.cs │ ├── Scanning │ │ ├── OpenGenericScanningRegistrationTests.cs │ │ └── ScanningRegistrationTests.cs │ └── Variance │ │ └── ContravariantRegistrationSourceTests.cs ├── Mocks.cs ├── ModuleTests.cs ├── NamedParameterTests.cs ├── ResolutionExtensionsTests.cs ├── Scenarios │ ├── Adapters │ │ ├── AnotherCommand.cs │ │ ├── Command.cs │ │ ├── IToolbarButton.cs │ │ └── ToolbarButton.cs │ ├── ConstructorSelection │ │ └── MultipleConstructors.cs │ ├── Dependencies │ │ ├── Circularity │ │ │ ├── A.cs │ │ │ ├── BC.cs │ │ │ ├── D.cs │ │ │ ├── IA.cs │ │ │ ├── IB.cs │ │ │ ├── IC.cs │ │ │ └── ID.cs │ │ ├── Dependent.cs │ │ ├── DependsByCtor.cs │ │ └── DependsByProp.cs │ ├── Graph1 │ │ ├── A1.cs │ │ ├── B1.cs │ │ ├── C1.cs │ │ ├── CD1.cs │ │ ├── E1.cs │ │ ├── F1.cs │ │ ├── IC1.cs │ │ └── ID1.cs │ ├── Parameterization │ │ └── Parameterized.cs │ ├── RegistrationSources │ │ └── ObjectRegistrationSource.cs │ └── WithProperty │ │ └── WithProps.cs ├── SourceRegistrationExtensionsTests.cs ├── TagsFixture.cs ├── TypeExtensionsTests.cs ├── TypedParameterTests.cs └── Util │ ├── AsyncDisposeTracker.cs │ ├── AsyncOnlyDisposeTracker.cs │ ├── Cache │ ├── ReflectionCacheAssemblyDictionaryTests.cs │ ├── ReflectionCacheDictionaryTests.cs │ ├── ReflectionCacheTupleDictionaryTests.cs │ └── TypeAssemblyReferenceProviderTests.cs │ ├── DelegateExtensionsTests.cs │ ├── DisposeTracker.cs │ ├── EnforceTests.cs │ ├── FallbackDictionaryTests.cs │ ├── InternalTypeExtensionsTests.cs │ └── SequenceGeneratorTests.cs ├── README.md └── Shims └── required ├── .editorconfig ├── CompilerFeatureRequiredAttribute.cs ├── README.md ├── RequiredMemberAttribute.cs └── SetsRequiredMembersAttribute.cs /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Ignore revisions in git blame - set your git config to use the file by convention: 2 | # git config --global blame.ignoreRevsFile .git-blame-ignore-revs 3 | # 4 | # Optional additional git config: 5 | # Mark any lines that have had a commit skipped using --ignore-rev with a `?` 6 | # git config --global blame.markIgnoredLines true 7 | # Mark any lines that were added in a skipped commit and can not be attributed with a `*` 8 | # git config --global blame.markUnblamableLines true 9 | 10 | # Convert to file-scoped namespaces. 11 | 48039bd166a76ad7935e3c66eb608fd08b0889fc 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.rb text=auto 26 | *.java text=auto 27 | *.html text=auto 28 | *.htm text=auto 29 | *.css text=auto 30 | *.scss text=auto 31 | *.sass text=auto 32 | *.less text=auto 33 | *.js text=auto 34 | *.lisp text=auto 35 | *.clj text=auto 36 | *.sql text=auto 37 | *.php text=auto 38 | *.lua text=auto 39 | *.m text=auto 40 | *.asm text=auto 41 | *.erl text=auto 42 | *.fs text=auto 43 | *.fsx text=auto 44 | *.hs text=auto 45 | 46 | *.csproj text=auto 47 | *.vbproj text=auto 48 | *.fsproj text=auto 49 | *.dbproj text=auto 50 | *.sln text=auto eol=crlf 51 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: 2 | - alistairjevans 3 | - tillig 4 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | on: 3 | workflow_call: 4 | secrets: 5 | CODECOV_TOKEN: 6 | description: Token for uploading code coverage metrics to CodeCov.io. 7 | required: true 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v4 14 | - name: Setup .NET 15 | uses: actions/setup-dotnet@v4 16 | with: 17 | dotnet-version: | 18 | 6.0.x 19 | 7.0.x 20 | 8.0.x 21 | - name: Build and test 22 | run: dotnet msbuild ./default.proj 23 | - name: Upload coverage 24 | uses: codecov/codecov-action@v5 25 | with: 26 | fail_ci_if_error: true 27 | files: artifacts/logs/*/coverage.cobertura.xml 28 | token: ${{ secrets.CODECOV_TOKEN }} 29 | - name: Upload package artifacts 30 | uses: actions/upload-artifact@v4 31 | with: 32 | name: packages 33 | path: | 34 | artifacts/packages/*.nupkg 35 | artifacts/packages/*.snupkg 36 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Continuous Integration 2 | on: 3 | pull_request: 4 | branches: 5 | - develop 6 | - master 7 | push: 8 | branches: 9 | - develop 10 | - master 11 | - feature/* 12 | tags: 13 | - v[0-9]+.[0-9]+.[0-9]+ 14 | # If multiple pushes happen quickly in succession, cancel the running build and 15 | # start a new one. 16 | concurrency: 17 | group: ${{ github.workflow }}-${{ github.ref }} 18 | cancel-in-progress: true 19 | jobs: 20 | # Linting 21 | dotnet-format: 22 | uses: ./.github/workflows/dotnet-format.yml 23 | pre-commit: 24 | uses: ./.github/workflows/pre-commit.yml 25 | # Build and test 26 | build: 27 | uses: ./.github/workflows/build.yml 28 | secrets: 29 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 30 | # Publish beta and release packages. 31 | publish: 32 | uses: ./.github/workflows/publish.yml 33 | needs: 34 | - build 35 | - dotnet-format 36 | - pre-commit 37 | if: ${{ github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v') }} 38 | secrets: 39 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} 40 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-format.yml: -------------------------------------------------------------------------------- 1 | name: dotnet format 2 | on: 3 | workflow_call: 4 | jobs: 5 | dotnet-format: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v4 9 | - name: Setup .NET 8 10 | uses: actions/setup-dotnet@v4 11 | with: 12 | dotnet-version: 8.0.x 13 | - name: dotnet format 14 | run: dotnet format Autofac.sln --no-restore --verify-no-changes 15 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yml: -------------------------------------------------------------------------------- 1 | name: pre-commit 2 | on: 3 | workflow_call: 4 | jobs: 5 | pre-commit: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v4 9 | - uses: actions/setup-python@v5 10 | with: 11 | python-version: 3.x 12 | - uses: pre-commit/action@v3.0.1 13 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "MD013": false 3 | } 4 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: "cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b" # v5.0.0 4 | hooks: 5 | - id: check-json 6 | - id: check-yaml 7 | - id: check-merge-conflict 8 | - id: end-of-file-fixer 9 | - id: trailing-whitespace 10 | - repo: https://github.com/igorshubovych/markdownlint-cli 11 | rev: "586c3ea3f51230da42bab657c6a32e9e66c364f0" # v0.44.0 12 | hooks: 13 | - id: markdownlint 14 | args: 15 | - --fix 16 | - repo: https://github.com/tillig/json-sort-cli 17 | rev: "e49ea86dde26d69661d5de4ab738a7e14c6275b2" # v2.0.3 18 | hooks: 19 | - id: json-sort 20 | args: 21 | - --autofix 22 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-dotnettools.csdevkit", 4 | "editorconfig.editorconfig", 5 | "davidanson.vscode-markdownlint" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "actnars", 4 | "autofac", 5 | "autowired", 6 | "autowiring", 7 | "browsable", 8 | "cref", 9 | "diagnoser", 10 | "diagnosers", 11 | "finalizers", 12 | "inheritdoc", 13 | "langword", 14 | "netcoreapp", 15 | "netstandard", 16 | "notnull", 17 | "paramref", 18 | "startable", 19 | "subclassing", 20 | "typeparam", 21 | "unconfigured", 22 | "xunit" 23 | ], 24 | "dotnet.defaultSolution": "Autofac.sln", 25 | "explorer.fileNesting.enabled": true, 26 | "explorer.fileNesting.patterns": { 27 | "*.resx": "$(capture).*.resx, $(capture).designer.cs, $(capture).designer.vb" 28 | }, 29 | "omnisharp.enableEditorConfigSupport": true 30 | } 31 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "args": [ 5 | "build", 6 | "${workspaceFolder}/Autofac.sln", 7 | "/property:GenerateFullPaths=true", 8 | "/consoleloggerparameters:NoSummary" 9 | ], 10 | "command": "dotnet", 11 | "group": { 12 | "isDefault": true, 13 | "kind": "build" 14 | }, 15 | "label": "build", 16 | "problemMatcher": "$msCompile", 17 | "type": "shell" 18 | }, 19 | { 20 | "args": [ 21 | "test", 22 | "${workspaceFolder}/Autofac.sln", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary", 25 | "--filter", 26 | "FullyQualifiedName!~Benchmark" 27 | ], 28 | "command": "dotnet", 29 | "group": { 30 | "isDefault": true, 31 | "kind": "test" 32 | }, 33 | "label": "test", 34 | "problemMatcher": "$msCompile", 35 | "type": "process" 36 | } 37 | ], 38 | "version": "2.0.0" 39 | } 40 | -------------------------------------------------------------------------------- /Autofac.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/autofac/Autofac/3cb620ff184425889be663e90630e09bfbc30022/Autofac.snk -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2014 Autofac Project 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /bench/Autofac.BenchmarkProfiling/Autofac.BenchmarkProfiling.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Exe 4 | net8.0 5 | $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) 6 | ../../build/Test.ruleset 7 | AllEnabledByDefault 8 | true 9 | false 10 | enable 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /bench/Autofac.BenchmarkProfiling/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Autofac.BenchmarkProfiling": { 4 | "commandLineArgs": "", 5 | "commandName": "Project" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/BenchmarkConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using BenchmarkDotNet.Configs; 3 | using BenchmarkDotNet.Diagnosers; 4 | 5 | namespace Autofac.Benchmarks; 6 | 7 | internal class BenchmarkConfig : ManualConfig 8 | { 9 | private const string BenchmarkArtifactsFolder = "BenchmarkDotNet.Artifacts"; 10 | 11 | internal BenchmarkConfig() 12 | { 13 | Add(DefaultConfig.Instance); 14 | 15 | var rootFolder = AppContext.BaseDirectory; 16 | var runFolder = DateTime.UtcNow.ToString("dd-MM-yyyy_hh-MM-ss", CultureInfo.InvariantCulture); 17 | ArtifactsPath = Path.Combine(rootFolder, BenchmarkArtifactsFolder, runFolder); 18 | 19 | AddDiagnoser(MemoryDiagnoser.Default); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/BenchmarkSet.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators; 2 | 3 | namespace Autofac.Benchmarks; 4 | 5 | public static class BenchmarkSet 6 | { 7 | public static readonly Type[] All = 8 | { 9 | typeof(ChildScopeResolveBenchmark), 10 | typeof(ConcurrencyBenchmark), 11 | typeof(ConcurrencyNestedScopeBenchmark), 12 | typeof(KeyedGenericBenchmark), 13 | typeof(KeyedNestedBenchmark), 14 | typeof(KeyedSimpleBenchmark), 15 | typeof(KeylessGenericBenchmark), 16 | typeof(KeylessNestedBenchmark), 17 | typeof(KeylessNestedSharedInstanceBenchmark), 18 | typeof(KeylessNestedLambdaBenchmark), 19 | typeof(KeylessNestedSharedInstanceLambdaBenchmark), 20 | typeof(KeylessSimpleBenchmark), 21 | typeof(KeylessSimpleSharedInstanceBenchmark), 22 | typeof(KeylessSimpleLambdaBenchmark), 23 | typeof(KeylessSimpleSharedInstanceLambdaBenchmark), 24 | typeof(DeepGraphResolveBenchmark), 25 | typeof(EnumerableResolveBenchmark), 26 | typeof(PropertyInjectionBenchmark), 27 | typeof(RootContainerResolveBenchmark), 28 | typeof(OpenGenericBenchmark), 29 | typeof(MultiConstructorBenchmark), 30 | typeof(LambdaResolveBenchmark), 31 | typeof(RequiredPropertyBenchmark), 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeyedGenericBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the simple/common use case for open generic decorators using the keyed syntax. 7 | /// 8 | public class KeyedGenericBenchmark : DecoratorBenchmarkBase> 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterGeneric(typeof(GenericCommandHandlerOne<>)) 16 | .Named("handler", typeof(ICommandHandler<>)); 17 | builder.RegisterGeneric(typeof(GenericCommandHandlerTwo<>)) 18 | .Named("handler", typeof(ICommandHandler<>)); 19 | 20 | builder.RegisterGenericDecorator( 21 | typeof(GenericCommandHandlerDecorator<>), 22 | typeof(ICommandHandler<>), 23 | fromKey: "handler"); 24 | 25 | Container = builder.Build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeyedNestedBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks a more complex case of chaining decorators using the keyed syntax. 7 | /// 8 | public class KeyedNestedBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .Named("handler"); 17 | builder.RegisterType() 18 | .Named("handler"); 19 | builder.RegisterDecorator( 20 | (c, inner) => new CommandHandlerDecoratorOne(inner), 21 | fromKey: "handler", toKey: "decorated"); 22 | builder.RegisterDecorator( 23 | (c, inner) => new CommandHandlerDecoratorTwo(inner), 24 | fromKey: "decorated"); 25 | 26 | Container = builder.Build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeyedSimpleBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the simple/common use case for decorators using the keyed syntax. 7 | /// 8 | public class KeyedSimpleBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .Named("handler"); 17 | builder.RegisterType() 18 | .Named("handler"); 19 | builder.RegisterDecorator( 20 | (c, inner) => new CommandHandlerDecoratorOne(inner), 21 | fromKey: "handler"); 22 | 23 | Container = builder.Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessGenericBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the simple/common use case for open generic decorators using the new keyless syntax. 7 | /// 8 | public class KeylessGenericBenchmark : DecoratorBenchmarkBase> 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterGeneric(typeof(GenericCommandHandlerOne<>)) 16 | .As(typeof(ICommandHandler<>)); 17 | builder.RegisterGeneric(typeof(GenericCommandHandlerTwo<>)) 18 | .As(typeof(ICommandHandler<>)); 19 | builder.RegisterGenericDecorator( 20 | typeof(GenericCommandHandlerTwo<>), 21 | typeof(ICommandHandler<>)); 22 | 23 | Container = builder.Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessNestedBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks a more complex case of chaining decorators using the new keyless syntax. 7 | /// 8 | public class KeylessNestedBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .As(); 17 | builder.RegisterType() 18 | .As(); 19 | builder.RegisterDecorator(); 20 | builder.RegisterDecorator(); 21 | 22 | Container = builder.Build(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessNestedLambdaBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks a more complex case of chaining decorators using the new keyless syntax. 7 | /// 8 | public class KeylessNestedLambdaBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .As(); 17 | builder.RegisterType() 18 | .As(); 19 | builder.RegisterDecorator( 20 | (c, p, i) => new CommandHandlerDecoratorOne(i)); 21 | builder.RegisterDecorator( 22 | (c, p, i) => new CommandHandlerDecoratorTwo(i)); 23 | 24 | Container = builder.Build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessNestedSharedInstanceBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks a more complex case of chaining decorators using the new keyless syntax. 7 | /// 8 | public class KeylessNestedSharedInstanceBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .As() 17 | .InstancePerLifetimeScope(); 18 | builder.RegisterType() 19 | .As() 20 | .InstancePerLifetimeScope(); 21 | builder.RegisterDecorator(); 22 | builder.RegisterDecorator(); 23 | 24 | Container = builder.Build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessNestedSharedInstanceLambdaBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks a more complex case of chaining decorators using the new keyless syntax. 7 | /// 8 | public class KeylessNestedSharedInstanceLambdaBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .As() 17 | .InstancePerLifetimeScope(); 18 | builder.RegisterType() 19 | .As() 20 | .InstancePerLifetimeScope(); 21 | builder.RegisterDecorator( 22 | (c, p, i) => new CommandHandlerDecoratorOne(i)); 23 | builder.RegisterDecorator( 24 | (c, p, i) => new CommandHandlerDecoratorTwo(i)); 25 | 26 | Container = builder.Build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessSimpleBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the simple/common use case for decorators using the new keyless syntax. 7 | /// 8 | public class KeylessSimpleBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | builder.RegisterType() 15 | .As(); 16 | builder.RegisterType() 17 | .As(); 18 | builder.RegisterDecorator(); 19 | Container = builder.Build(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessSimpleLambdaBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the simple/common use case for decorators using the new keyless syntax. 7 | /// 8 | public class KeylessSimpleLambdaBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType() 16 | .As(); 17 | builder.RegisterType() 18 | .As(); 19 | builder.RegisterDecorator((c, p, i) => new CommandHandlerDecoratorOne(i)); 20 | 21 | Container = builder.Build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessSimpleSharedInstanceBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the shared instance case for decorators using the new keyless syntax. 7 | /// 8 | public class KeylessSimpleSharedInstanceBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | builder.RegisterType() 15 | .As() 16 | .InstancePerLifetimeScope(); 17 | builder.RegisterType() 18 | .As() 19 | .InstancePerLifetimeScope(); 20 | builder.RegisterDecorator(); 21 | Container = builder.Build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/KeylessSimpleSharedInstanceLambdaBenchmark.cs: -------------------------------------------------------------------------------- 1 | using Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | namespace Autofac.Benchmarks.Decorators; 4 | 5 | /// 6 | /// Benchmarks the shared instance case for decorators using the new keyless syntax. 7 | /// 8 | public class KeylessSimpleSharedInstanceLambdaBenchmark : DecoratorBenchmarkBase 9 | { 10 | [GlobalSetup] 11 | public void Setup() 12 | { 13 | var builder = new ContainerBuilder(); 14 | builder.RegisterType() 15 | .As() 16 | .InstancePerLifetimeScope(); 17 | builder.RegisterType() 18 | .As() 19 | .InstancePerLifetimeScope(); 20 | builder.RegisterDecorator((c, p, i) => new CommandHandlerDecoratorOne(i)); 21 | Container = builder.Build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/Command.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class Command 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/CommandHandlerDecoratorOne.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class CommandHandlerDecoratorOne : ICommandHandler 4 | { 5 | public CommandHandlerDecoratorOne(ICommandHandler decorated) 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/CommandHandlerDecoratorTwo.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class CommandHandlerDecoratorTwo : ICommandHandler 4 | { 5 | public CommandHandlerDecoratorTwo(ICommandHandler decorated) 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/CommandHandlerOne.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class CommandHandlerOne : ICommandHandler 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/CommandHandlerTwo.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class CommandHandlerTwo : ICommandHandler 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/GenericCommandHandlerDecorator.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class GenericCommandHandlerDecorator : ICommandHandler 4 | { 5 | public GenericCommandHandlerDecorator(ICommandHandler decorated) 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/GenericCommandHandlerOne.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class GenericCommandHandlerOne : ICommandHandler 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/GenericCommandHandlerTwo.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public class GenericCommandHandlerTwo : ICommandHandler 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/ICommandHandler.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public interface ICommandHandler 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Decorators/Scenario/ICommandHandler`1.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks.Decorators.Scenario; 2 | 3 | public interface ICommandHandler 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/OpenGenericBenchmark.cs: -------------------------------------------------------------------------------- 1 | namespace Autofac.Benchmarks; 2 | 3 | public class OpenGenericBenchmark 4 | { 5 | private IContainer _container; 6 | 7 | [GlobalSetup] 8 | public void Setup() 9 | { 10 | var builder = new ContainerBuilder(); 11 | builder.RegisterGeneric(typeof(Service<>)).As(typeof(IService<>)); 12 | _container = builder.Build(); 13 | } 14 | 15 | [Benchmark] 16 | public void ResolveOpenGeneric() => _container.Resolve>(); 17 | 18 | private interface IService 19 | { 20 | } 21 | 22 | private class Service : IService 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 1 | using BenchmarkDotNet.Running; 2 | 3 | namespace Autofac.Benchmarks; 4 | 5 | internal static class Program 6 | { 7 | internal static void Main(string[] args) => 8 | new BenchmarkSwitcher(BenchmarkSet.All).Run(args, new BenchmarkConfig()); 9 | } 10 | -------------------------------------------------------------------------------- /bench/Autofac.Benchmarks/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "shadowCopy": false 3 | } 4 | -------------------------------------------------------------------------------- /build/Coverage.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | cobertura 8 | [System.*]* 9 | **/LoggerMessage.g.cs 10 | GeneratedCodeAttribute 11 | false 12 | true 13 | false 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /build/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/autofac/Autofac/3cb620ff184425889be663e90630e09bfbc30022/build/icon.png -------------------------------------------------------------------------------- /build/stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "documentationRules": { 5 | "companyName": "Autofac Project", 6 | "copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} License. See {licenseFile} in the project root for license information.", 7 | "variables": { 8 | "licenseFile": "LICENSE", 9 | "licenseName": "MIT" 10 | }, 11 | "xmlHeader": false 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | branch: develop 3 | require_ci_to_pass: true 4 | coverage: 5 | status: 6 | project: 7 | default: 8 | threshold: 1% 9 | -------------------------------------------------------------------------------- /codegen/Autofac.CodeGen/Autofac.CodeGen.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.0 4 | 5 | false 6 | enable 7 | latest 8 | ../../Autofac.snk 9 | true 10 | ../../build/Source.ruleset 11 | true 12 | AllEnabledByDefault 13 | enable 14 | true 15 | true 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /codegen/Autofac.CodeGen/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | [assembly: CLSCompliant(false)] 7 | [assembly: ComVisible(false)] 8 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "rollForward": "latestFeature", 4 | "version": "8.0.408" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/Autofac/Builder/ConcreteReflectionActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | using Autofac.Core.Activators.Reflection; 6 | 7 | namespace Autofac.Builder; 8 | 9 | /// 10 | /// Reflection activator data for concrete types. 11 | /// 12 | public class ConcreteReflectionActivatorData : ReflectionActivatorData, IConcreteActivatorData 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// Type that will be activated. 18 | public ConcreteReflectionActivatorData(Type implementer) 19 | : base(implementer) 20 | { 21 | } 22 | 23 | /// 24 | /// Gets the instance activator based on the provided data. 25 | /// 26 | public IInstanceActivator Activator => new ReflectionActivator( 27 | ImplementationType, 28 | ConstructorFinder, 29 | ConstructorSelector, 30 | ConfiguredParameters, 31 | ConfiguredProperties); 32 | } 33 | -------------------------------------------------------------------------------- /src/Autofac/Builder/ContainerBuildOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Builder; 5 | 6 | /// 7 | /// Behaviors for the construction of a container by a . 8 | /// 9 | [Flags] 10 | public enum ContainerBuildOptions 11 | { 12 | /// 13 | /// No options - the default behavior for container building. 14 | /// 15 | None = 0, 16 | 17 | /// 18 | /// Prevents inclusion of standard modules like support for 19 | /// relationship types including etc. 20 | /// 21 | ExcludeDefaultModules = 2, 22 | 23 | /// 24 | /// Does not call on components implementing 25 | /// this interface (useful for module testing.) 26 | /// 27 | IgnoreStartableComponents = 4, 28 | } 29 | -------------------------------------------------------------------------------- /src/Autofac/Builder/DynamicRegistrationStyle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Builder; 5 | 6 | /// 7 | /// Registration style for dynamic registrations. 8 | /// 9 | public class DynamicRegistrationStyle 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /src/Autofac/Builder/IConcreteActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Builder; 7 | 8 | /// 9 | /// Activator data that can provide an IInstanceActivator instance. 10 | /// 11 | public interface IConcreteActivatorData 12 | { 13 | /// 14 | /// Gets the instance activator based on the provided data. 15 | /// 16 | IInstanceActivator Activator { get; } 17 | } 18 | -------------------------------------------------------------------------------- /src/Autofac/Builder/SimpleActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Builder; 7 | 8 | /// 9 | /// An activator builder with no parameters. 10 | /// 11 | public class SimpleActivatorData : IConcreteActivatorData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The activator to return. 17 | public SimpleActivatorData(IInstanceActivator activator) 18 | { 19 | Activator = activator ?? throw new ArgumentNullException(nameof(activator)); 20 | } 21 | 22 | /// 23 | /// Gets the activator. 24 | /// 25 | public IInstanceActivator Activator { get; } 26 | } 27 | -------------------------------------------------------------------------------- /src/Autofac/Builder/SingleRegistrationStyle.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Builder; 7 | 8 | /// 9 | /// Registration style for individual components. 10 | /// 11 | public class SingleRegistrationStyle 12 | { 13 | /// 14 | /// Gets or sets the ID used for the registration. 15 | /// 16 | public Guid Id { get; set; } = Guid.NewGuid(); 17 | 18 | /// 19 | /// Gets the handlers to notify of the component registration event. 20 | /// 21 | public ICollection> RegisteredHandlers { get; } = new List>(); 22 | 23 | /// 24 | /// Gets or sets a value indicating whether default registrations should be preserved. 25 | /// By default, new registrations override existing registrations as defaults. 26 | /// If set to true, new registrations will not change existing defaults. 27 | /// 28 | public bool PreserveDefaults { get; set; } 29 | 30 | /// 31 | /// Gets or sets the component upon which this registration is based. 32 | /// 33 | public IComponentRegistration? Target { get; set; } 34 | } 35 | -------------------------------------------------------------------------------- /src/Autofac/Core/Activators/DelegatePropertySelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | 6 | namespace Autofac.Core; 7 | 8 | /// 9 | /// Provides a property selector that applies a filter defined by a delegate. 10 | /// 11 | public sealed class DelegatePropertySelector : IPropertySelector 12 | { 13 | private readonly Func _finder; 14 | 15 | /// 16 | /// Initializes a new instance of the class 17 | /// that invokes a delegate to determine selection. 18 | /// 19 | /// Delegate to determine whether a property should be injected. 20 | public DelegatePropertySelector(Func finder) 21 | { 22 | _finder = finder ?? throw new ArgumentNullException(nameof(finder)); 23 | } 24 | 25 | /// 26 | public bool InjectProperty(PropertyInfo propertyInfo, object instance) 27 | { 28 | return _finder(propertyInfo, instance); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Autofac/Core/Activators/IPropertySelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | 6 | namespace Autofac.Core; 7 | 8 | /// 9 | /// Finds suitable properties to inject. 10 | /// 11 | public interface IPropertySelector 12 | { 13 | /// 14 | /// Provides filtering to determine if property should be injected. 15 | /// 16 | /// Property to be injected. 17 | /// Instance that has the property to be injected. 18 | /// Whether property should be injected. 19 | bool InjectProperty(PropertyInfo propertyInfo, object instance); 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Core/Activators/Reflection/IConstructorFinder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | 6 | namespace Autofac.Core.Activators.Reflection; 7 | 8 | /// 9 | /// Find suitable constructors from which to select. 10 | /// 11 | public interface IConstructorFinder 12 | { 13 | /// 14 | /// Finds suitable constructors on the target type. 15 | /// 16 | /// Type to search for constructors. 17 | /// Suitable constructors. 18 | ConstructorInfo[] FindConstructors(Type targetType); 19 | } 20 | -------------------------------------------------------------------------------- /src/Autofac/Core/Activators/Reflection/IConstructorSelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Activators.Reflection; 5 | 6 | /// 7 | /// Selects the best constructor from a set of available constructors. 8 | /// 9 | public interface IConstructorSelector 10 | { 11 | /// 12 | /// Selects the best constructor from the available constructors. 13 | /// 14 | /// Available constructors. 15 | /// Parameters to the instance being resolved. 16 | /// The best constructor. 17 | BoundConstructor SelectConstructorBinding(BoundConstructor[] constructorBindings, IEnumerable parameters); 18 | } 19 | -------------------------------------------------------------------------------- /src/Autofac/Core/Activators/Reflection/InjectablePropertyState.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Activators.Reflection; 5 | 6 | /// 7 | /// Structure used to track whether or not we have set a property during activation. 8 | /// 9 | internal struct InjectablePropertyState 10 | { 11 | /// 12 | /// Initializes a new instance of the struct. 13 | /// 14 | /// The property. 15 | public InjectablePropertyState(InjectableProperty property) 16 | { 17 | Property = property; 18 | Set = false; 19 | } 20 | 21 | /// 22 | /// Gets the property. 23 | /// 24 | public InjectableProperty Property { get; } 25 | 26 | /// 27 | /// Gets or sets a value indicating whether this property has already been set. 28 | /// 29 | public bool Set { get; set; } 30 | } 31 | -------------------------------------------------------------------------------- /src/Autofac/Core/IActivatedEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Fired when the activation process for a new instance is complete. 8 | /// 9 | [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] 10 | public interface IActivatedEventArgs 11 | { 12 | /// 13 | /// Gets the service being resolved. 14 | /// 15 | Service Service { get; } 16 | 17 | /// 18 | /// Gets the context in which the activation occurred. 19 | /// 20 | IComponentContext Context { get; } 21 | 22 | /// 23 | /// Gets the component providing the instance. 24 | /// 25 | IComponentRegistration Component { get; } 26 | 27 | /// 28 | /// Gets the paramters provided when resolved. 29 | /// 30 | IEnumerable Parameters { get; } 31 | 32 | /// 33 | /// Gets the instance that will be used to satisfy the request. 34 | /// 35 | T Instance { get; } 36 | } 37 | -------------------------------------------------------------------------------- /src/Autofac/Core/IComponentLifetime.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Locates the lifetime to which instances of a component should be attached. 8 | /// 9 | public interface IComponentLifetime 10 | { 11 | /// 12 | /// Given the most nested scope visible within the resolve operation, find 13 | /// the scope for the component. 14 | /// 15 | /// The most nested visible scope. 16 | /// The scope for the component. 17 | ISharingLifetimeScope FindScope(ISharingLifetimeScope mostNestedVisibleScope); 18 | } 19 | -------------------------------------------------------------------------------- /src/Autofac/Core/IInstanceActivator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Core; 7 | 8 | /// 9 | /// Activates component instances. 10 | /// 11 | public interface IInstanceActivator : IDisposable 12 | { 13 | /// 14 | /// Allows an implementation to add middleware to a registration's resolve pipeline. 15 | /// 16 | /// Provides access to the set of all available services. 17 | /// The registration's pipeline builder. 18 | void ConfigurePipeline(IComponentRegistryServices componentRegistryServices, IResolvePipelineBuilder pipelineBuilder); 19 | 20 | /// 21 | /// Gets the most specific type that the component instances are known to be castable to. 22 | /// 23 | Type LimitType { get; } 24 | } 25 | -------------------------------------------------------------------------------- /src/Autofac/Core/IModule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Registration; 5 | 6 | namespace Autofac.Core; 7 | 8 | /// 9 | /// Represents a set of components and related functionality 10 | /// packaged together. 11 | /// 12 | public interface IModule 13 | { 14 | /// 15 | /// Apply the module to the component registry. 16 | /// 17 | /// Component registry to apply configuration to. 18 | void Configure(IComponentRegistryBuilder componentRegistry); 19 | } 20 | -------------------------------------------------------------------------------- /src/Autofac/Core/IServiceWithType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Interface supported by services that carry type information. 8 | /// 9 | public interface IServiceWithType 10 | { 11 | /// 12 | /// Gets the type of the service. 13 | /// 14 | /// The type of the service. 15 | Type ServiceType { get; } 16 | 17 | /// 18 | /// Return a new service of the same kind, but carrying 19 | /// as the . 20 | /// 21 | /// The new service type. 22 | /// A new service with the service type. 23 | Service ChangeType(Type newType); 24 | } 25 | -------------------------------------------------------------------------------- /src/Autofac/Core/InstanceOwnership.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Determines when instances supporting IDisposable are disposed. 8 | /// 9 | public enum InstanceOwnership 10 | { 11 | /// 12 | /// The lifetime scope does not dispose the instances. 13 | /// 14 | ExternallyOwned, 15 | 16 | /// 17 | /// The instances are disposed when the lifetime scope is disposed. 18 | /// 19 | OwnedByLifetimeScope, 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Core/InstanceSharing.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Determines whether instances are shared within a lifetime scope. 8 | /// 9 | public enum InstanceSharing 10 | { 11 | /// 12 | /// Each request for an instance will return a new object. 13 | /// 14 | None, 15 | 16 | /// 17 | /// Each request for an instance will return the same object. 18 | /// 19 | Shared, 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Core/Lifetime/CurrentScopeLifetime.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Lifetime; 5 | 6 | /// 7 | /// Attaches the instance's lifetime to the current lifetime scope. 8 | /// 9 | public class CurrentScopeLifetime : IComponentLifetime 10 | { 11 | /// 12 | /// Gets the singleton instance of the behaviour. 13 | /// 14 | public static IComponentLifetime Instance { get; } = new CurrentScopeLifetime(); 15 | 16 | /// 17 | /// Given the most nested scope visible within the resolve operation, find 18 | /// the scope for the component. 19 | /// 20 | /// The most nested visible scope. 21 | /// The scope for the component. 22 | public ISharingLifetimeScope FindScope(ISharingLifetimeScope mostNestedVisibleScope) 23 | { 24 | if (mostNestedVisibleScope == null) 25 | { 26 | throw new ArgumentNullException(nameof(mostNestedVisibleScope)); 27 | } 28 | 29 | return mostNestedVisibleScope; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Autofac/Core/Lifetime/LifetimeScopeBeginningEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Lifetime; 5 | 6 | /// 7 | /// Describes when a lifetime scope is beginning. 8 | /// 9 | public class LifetimeScopeBeginningEventArgs : EventArgs 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The lifetime scope that is beginning. 15 | public LifetimeScopeBeginningEventArgs(ILifetimeScope lifetimeScope) 16 | { 17 | LifetimeScope = lifetimeScope; 18 | } 19 | 20 | /// 21 | /// Gets the lifetime scope that is beginning. 22 | /// 23 | public ILifetimeScope LifetimeScope { get; } 24 | } 25 | -------------------------------------------------------------------------------- /src/Autofac/Core/Lifetime/LifetimeScopeEndingEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Lifetime; 5 | 6 | /// 7 | /// Describes when a lifetime scope is ending. 8 | /// 9 | public class LifetimeScopeEndingEventArgs : EventArgs 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The lifetime scope that is ending. 15 | public LifetimeScopeEndingEventArgs(ILifetimeScope lifetimeScope) 16 | { 17 | LifetimeScope = lifetimeScope; 18 | } 19 | 20 | /// 21 | /// Gets the lifetime scope that is ending. 22 | /// 23 | public ILifetimeScope LifetimeScope { get; } 24 | } 25 | -------------------------------------------------------------------------------- /src/Autofac/Core/Lifetime/MatchingScopeLifetimeTags.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Lifetime; 5 | 6 | /// 7 | /// Well-known tags used in setting up matching lifetime scopes. 8 | /// 9 | public static class MatchingScopeLifetimeTags 10 | { 11 | /// 12 | /// Tag used in setting up per-request lifetime scope registrations 13 | /// (e.g., per-HTTP-request or per-API-request). 14 | /// 15 | public static readonly object RequestLifetimeScopeTag = "AutofacWebRequest"; 16 | } 17 | -------------------------------------------------------------------------------- /src/Autofac/Core/Lifetime/RootScopeLifetime.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Lifetime; 5 | 6 | /// 7 | /// Attaches the component's lifetime to the root scope. 8 | /// 9 | public class RootScopeLifetime : IComponentLifetime 10 | { 11 | /// 12 | /// Gets the singleton instance of the behaviour. 13 | /// 14 | public static IComponentLifetime Instance { get; } = new RootScopeLifetime(); 15 | 16 | /// 17 | /// Given the most nested scope visible within the resolve operation, find 18 | /// the scope for the component. 19 | /// 20 | /// The most nested visible scope. 21 | /// The scope for the component. 22 | public ISharingLifetimeScope FindScope(ISharingLifetimeScope mostNestedVisibleScope) 23 | { 24 | if (mostNestedVisibleScope == null) 25 | { 26 | throw new ArgumentNullException(nameof(mostNestedVisibleScope)); 27 | } 28 | 29 | return mostNestedVisibleScope.RootLifetimeScope; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Autofac/Core/NamedPropertyParameter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | using Autofac.Util; 6 | 7 | namespace Autofac.Core; 8 | 9 | /// 10 | /// A property identified by name. When applied to a reflection-based 11 | /// component, the name will be matched against property names. 12 | /// 13 | public class NamedPropertyParameter : ConstantParameter 14 | { 15 | /// 16 | /// Gets the name of the property. 17 | /// 18 | public string Name { get; private set; } 19 | 20 | /// 21 | /// Initializes a new instance of the class. 22 | /// 23 | /// The name of the property. 24 | /// The property value. 25 | public NamedPropertyParameter(string name, object? value) 26 | : base(value, pi => 27 | { 28 | return pi.TryGetDeclaringProperty(out PropertyInfo? prop) && 29 | prop.Name == name; 30 | }) 31 | { 32 | Name = Enforce.ArgumentNotNullOrEmpty(name, "name"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Autofac/Core/ReflectionCacheUsage.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Defines the possible reflection cache usage types. 8 | /// 9 | [Flags] 10 | public enum ReflectionCacheUsage 11 | { 12 | /// 13 | /// The cache isn't used (not generally a valid value). 14 | /// 15 | None = 0x00, 16 | 17 | /// 18 | /// The cache is used at registration time. 19 | /// 20 | Registration = 0x01, 21 | 22 | /// 23 | /// The cache is used after registration, during registration. 24 | /// 25 | Resolution = 0x02, 26 | 27 | /// 28 | /// The cache is used during all stages (registration and resolution). 29 | /// 30 | All = Registration | Resolution, 31 | } 32 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/ComponentRegistrationExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Registration; 5 | 6 | /// 7 | /// Internal Extension methods for component registrations. 8 | /// 9 | internal static class ComponentRegistrationExtensions 10 | { 11 | /// 12 | /// Gets a value indicating whether a given registration is adapting another registration. 13 | /// 14 | /// The component registration. 15 | /// True if adapting; false otherwise. 16 | public static bool IsAdapting(this IComponentRegistration componentRegistration) 17 | { 18 | return componentRegistration.Target != componentRegistration; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/IModuleRegistrar.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.ComponentModel; 5 | 6 | namespace Autofac.Core.Registration; 7 | 8 | /// 9 | /// Interface providing fluent syntax for chaining module registrations. 10 | /// 11 | public interface IModuleRegistrar 12 | { 13 | /// 14 | /// Gets the registrar data. 15 | /// 16 | [EditorBrowsable(EditorBrowsableState.Never)] 17 | public ModuleRegistrarData RegistrarData { get; } 18 | 19 | /// 20 | /// Add a module to the container. 21 | /// 22 | /// The module to add. 23 | /// 24 | /// The to allow 25 | /// additional chained module registrations. 26 | /// 27 | IModuleRegistrar RegisterModule(IModule module); 28 | } 29 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/IPerScopeRegistrationSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Registration; 5 | 6 | /// 7 | /// Indicates that a registration source operates per-scope, and should not provide 8 | /// registrations for requests from child scopes. 9 | /// 10 | [SuppressMessage("Design", "CA1040:Avoid empty interfaces", Justification = "Need a marker interface of per-scope registration sources")] 11 | public interface IPerScopeRegistrationSource 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/IServiceMiddlewareSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Core.Registration; 7 | 8 | /// 9 | /// Interface defining a source of middleware for a service's pipeline. 10 | /// 11 | public interface IServiceMiddlewareSource 12 | { 13 | /// 14 | /// Called when a service is first resolved; implementations can add middleware to the service using the . 15 | /// 16 | /// The service being resolved. 17 | /// Access to the set of available service registrations. 18 | /// A pipeline builder that can be used to add middleware. 19 | void ProvideMiddleware(Service service, IComponentRegistryServices availableServices, IResolvePipelineBuilder pipelineBuilder); 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/IServiceMiddlewareSourceRegistrar.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Registration; 5 | 6 | /// 7 | /// Interface providing fluent syntax for chaining middleware source registrations. 8 | /// 9 | public interface IServiceMiddlewareSourceRegistrar 10 | { 11 | /// 12 | /// Adds a middleware source to the container. 13 | /// 14 | /// The middleware source to add. 15 | /// 16 | /// The to allow additional chained middleware source registrations. 17 | /// 18 | IServiceMiddlewareSourceRegistrar RegisterServiceMiddlewareSource(IServiceMiddlewareSource serviceMiddlewareSource); 19 | } 20 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/ISourceRegistrar.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Registration; 5 | 6 | /// 7 | /// Interface providing fluent syntax for chaining registration source registrations. 8 | /// 9 | public interface ISourceRegistrar 10 | { 11 | /// 12 | /// Add a registration source to the container. 13 | /// 14 | /// The registration source to add. 15 | /// 16 | /// The to allow additional chained registration source registrations. 17 | /// 18 | ISourceRegistrar RegisterSource(IRegistrationSource registrationSource); 19 | } 20 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/ModuleRegistrarData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Builder; 5 | 6 | namespace Autofac.Core.Registration; 7 | 8 | /// 9 | /// Data used by to support customisations to the module registration process. 10 | /// 11 | public class ModuleRegistrarData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The callback for the registrar. 17 | public ModuleRegistrarData(DeferredCallback callback) 18 | { 19 | Callback = callback; 20 | } 21 | 22 | /// 23 | /// Gets the callback invoked when the collection of modules attached to this registrar are registered. 24 | /// 25 | public DeferredCallback Callback { get; } 26 | } 27 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/RegistrationOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Registration; 5 | 6 | /// 7 | /// Defines options for a registration. 8 | /// 9 | [Flags] 10 | public enum RegistrationOptions 11 | { 12 | /// 13 | /// No special options; default behaviour. 14 | /// 15 | None = 0, 16 | 17 | /// 18 | /// Indicates that this registration is 'fixed' as the default, ignoring all other registrations when determining the default registration for 19 | /// a service. 20 | /// 21 | Fixed = 2, 22 | 23 | /// 24 | /// Registrations with this flag will not be decorated. 25 | /// 26 | DisableDecoration = 4, 27 | 28 | /// 29 | /// Registrations with this flag will not be included in any collection resolves (i.e. and other collection types). 30 | /// 31 | ExcludeFromCollections = 8, 32 | 33 | /// 34 | /// Flag combination for composite registrations. 35 | /// 36 | Composite = Fixed | DisableDecoration | ExcludeFromCollections, 37 | } 38 | -------------------------------------------------------------------------------- /src/Autofac/Core/Registration/RegistrationOptionsExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Registration; 5 | 6 | /// 7 | /// Extension methods for registration options. 8 | /// 9 | public static class RegistrationOptionsExtensions 10 | { 11 | /// 12 | /// Tests whether a given flag (or combined set of flags) is present in the specified 13 | /// options enumeration. 14 | /// 15 | /// The option to test. 16 | /// The flag (or flags) to test for. 17 | /// True if the specified flag (or flags) are enabled for the registration. 18 | public static bool HasOption(this RegistrationOptions options, RegistrationOptions flag) 19 | { 20 | return (options & flag) == flag; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/ActivatorExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Activators.Delegate; 5 | 6 | namespace Autofac.Core.Resolving; 7 | 8 | /// 9 | /// Extension methods for activators. 10 | /// 11 | internal static class ActivatorExtensions 12 | { 13 | /// 14 | /// This shorthand name for the activator is used in exception messages; for activator types 15 | /// where the limit type generally describes the activator exactly, we use that; for delegate 16 | /// activators, a variation on the type name is used to indicate this. 17 | /// 18 | /// The activator instance. 19 | /// A display name. 20 | public static string DisplayName(this IInstanceActivator activator) 21 | { 22 | var fullName = activator?.LimitType.FullName ?? ""; 23 | return activator is DelegateActivator ? 24 | $"λ:{fullName}" : 25 | fullName; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/Middleware/RegistrationPipelineInvokeMiddleware.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Core.Resolving.Middleware; 7 | 8 | /// 9 | /// Middleware added by default to the end of all service pipelines that invokes the registration's pipeline. 10 | /// 11 | internal class RegistrationPipelineInvokeMiddleware : IResolveMiddleware 12 | { 13 | /// 14 | /// Gets the singleton instance of this middleware. 15 | /// 16 | public static RegistrationPipelineInvokeMiddleware Instance { get; } = new RegistrationPipelineInvokeMiddleware(); 17 | 18 | private RegistrationPipelineInvokeMiddleware() 19 | { 20 | } 21 | 22 | /// 23 | public PipelinePhase Phase => PipelinePhase.ServicePipelineEnd; 24 | 25 | /// 26 | public void Execute(ResolveRequestContext context, Action next) 27 | { 28 | context.Registration.ResolvePipeline.Invoke(context); 29 | } 30 | 31 | /// 32 | public override string ToString() => nameof(RegistrationPipelineInvokeMiddleware); 33 | } 34 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/Pipeline/IResolveMiddleware.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Resolving.Pipeline; 5 | 6 | /// 7 | /// Defines an executable resolve middleware. 8 | /// 9 | public interface IResolveMiddleware 10 | { 11 | /// 12 | /// Gets the phase of the resolve pipeline at which to execute. 13 | /// 14 | PipelinePhase Phase { get; } 15 | 16 | /// 17 | /// Invoked when this middleware is executed as part of an active . The middleware should usually call 18 | /// the method in order to continue the pipeline, unless the middleware fully satisfies the request. 19 | /// 20 | /// The context for the resolve request. 21 | /// The method to invoke to continue the pipeline execution; pass this method the argument. 22 | void Execute(ResolveRequestContext context, Action next); 23 | } 24 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/Pipeline/IResolvePipeline.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Resolving.Pipeline; 5 | 6 | /// 7 | /// Represents a pipeline that can be invoked to resolve an instance of a service. 8 | /// 9 | public interface IResolvePipeline 10 | { 11 | /// 12 | /// Invoke the pipeline to the end, or until an exception is thrown. 13 | /// 14 | /// The request context. 15 | void Invoke(ResolveRequestContext context); 16 | } 17 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/Pipeline/MiddlewareInsertionMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Resolving.Pipeline; 5 | 6 | /// 7 | /// Provides the modes of insertion when adding middleware to an . 8 | /// 9 | public enum MiddlewareInsertionMode 10 | { 11 | /// 12 | /// The new middleware should be added at the end of the middleware's declared phase. The added middleware will run after any middleware already added 13 | /// at the same phase. 14 | /// 15 | EndOfPhase, 16 | 17 | /// 18 | /// The new middleware should be added at the beginning of the middleware's declared phase. The added middleware will run before any middleware 19 | /// already added at the same phase. 20 | /// 21 | StartOfPhase, 22 | } 23 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/Pipeline/PipelineType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Resolving.Pipeline; 5 | 6 | /// 7 | /// Defines the possible pipeline types. 8 | /// 9 | public enum PipelineType 10 | { 11 | /// 12 | /// A service pipeline. Usually invokes a pipeline when it is finished. 13 | /// 14 | Service, 15 | 16 | /// 17 | /// A registration pipeline, used for activating a registration. 18 | /// 19 | Registration, 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/ResolveOperationBeginningEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Resolving; 5 | 6 | /// 7 | /// Describes the commencement of a new resolve operation. 8 | /// 9 | public sealed class ResolveOperationBeginningEventArgs : EventArgs 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The resolve operation that is beginning. 15 | public ResolveOperationBeginningEventArgs(IResolveOperation resolveOperation) 16 | { 17 | ResolveOperation = resolveOperation; 18 | } 19 | 20 | /// 21 | /// Gets the resolve operation that is beginning. 22 | /// 23 | public IResolveOperation ResolveOperation { get; } 24 | } 25 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/ResolveOperationEndingEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core.Resolving; 5 | 6 | /// 7 | /// Describes the commencement of a new resolve operation. 8 | /// 9 | public sealed class ResolveOperationEndingEventArgs : EventArgs 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The resolve operation that is ending. 15 | /// If included, the exception causing the operation to end; otherwise, null. 16 | public ResolveOperationEndingEventArgs(IResolveOperation resolveOperation, Exception? exception = null) 17 | { 18 | ResolveOperation = resolveOperation; 19 | Exception = exception; 20 | } 21 | 22 | /// 23 | /// Gets the exception causing the operation to end, or null. 24 | /// 25 | public Exception? Exception { get; } 26 | 27 | /// 28 | /// Gets the resolve operation that is ending. 29 | /// 30 | public IResolveOperation ResolveOperation { get; } 31 | } 32 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/ResolvePipeline.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Core.Pipeline; 7 | 8 | /// 9 | /// Encapsulates the call back that represents the entry point of a pipeline. 10 | /// 11 | internal class ResolvePipeline : IResolvePipeline 12 | { 13 | private readonly Action? _entryPoint; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// Callback to invoke. 19 | public ResolvePipeline(Action? entryPoint) 20 | { 21 | _entryPoint = entryPoint; 22 | } 23 | 24 | /// 25 | public void Invoke(ResolveRequestContext context) 26 | { 27 | _entryPoint?.Invoke(context); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/ResolveRequestBeginningEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Core.Resolving; 7 | 8 | /// 9 | /// Fired when a resolve request is starting. 10 | /// 11 | public sealed class ResolveRequestBeginningEventArgs : EventArgs 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The resolve request context that is starting. 17 | public ResolveRequestBeginningEventArgs(ResolveRequestContext requestContext) 18 | { 19 | RequestContext = requestContext ?? throw new ArgumentNullException(nameof(requestContext)); 20 | } 21 | 22 | /// 23 | /// Gets the resolve request that is beginning. 24 | /// 25 | public ResolveRequestContext RequestContext { get; } 26 | } 27 | -------------------------------------------------------------------------------- /src/Autofac/Core/Resolving/ResolveRequestCompletingEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Core.Resolving; 7 | 8 | /// 9 | /// Fired when a resolve request is starting. 10 | /// 11 | public class ResolveRequestCompletingEventArgs : EventArgs 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The resolve request context that is completing. 17 | public ResolveRequestCompletingEventArgs(ResolveRequestContext requestContext) 18 | { 19 | if (requestContext is null) 20 | { 21 | throw new ArgumentNullException(nameof(requestContext)); 22 | } 23 | 24 | RequestContext = requestContext; 25 | } 26 | 27 | /// 28 | /// Gets the instance lookup operation that is beginning. 29 | /// 30 | public ResolveRequestContext RequestContext { get; } 31 | } 32 | -------------------------------------------------------------------------------- /src/Autofac/Core/ScopeIsolatedService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Core; 5 | 6 | /// 7 | /// Decorator for a that indicates the service should 8 | /// be isolated from the current scope so references to it are not 9 | /// retained. Enables isolated services to be later unloaded. 10 | /// 11 | internal class ScopeIsolatedService : Service 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The service to wrap for isolation. 17 | public ScopeIsolatedService(Service service) 18 | { 19 | Service = service; 20 | } 21 | 22 | /// 23 | /// Gets the actual service that has been isolated. 24 | /// 25 | public Service Service { get; } 26 | 27 | /// 28 | public override string Description => Service.Description; 29 | } 30 | -------------------------------------------------------------------------------- /src/Autofac/Diagnostics/MiddlewareDiagnosticData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Pipeline; 5 | 6 | namespace Autofac.Diagnostics; 7 | 8 | /// 9 | /// Diagnostic data associated with middleware events. 10 | /// 11 | public class MiddlewareDiagnosticData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The context for the resolve request that is running. 17 | /// The middleware that is running. 18 | public MiddlewareDiagnosticData(ResolveRequestContext requestContext, IResolveMiddleware middleware) 19 | { 20 | RequestContext = requestContext; 21 | Middleware = middleware; 22 | } 23 | 24 | /// 25 | /// Gets the context for the resolve request that is running. 26 | /// 27 | public ResolveRequestContext RequestContext { get; private set; } 28 | 29 | /// 30 | /// Gets the middleware that is running. 31 | /// 32 | public IResolveMiddleware Middleware { get; private set; } 33 | } 34 | -------------------------------------------------------------------------------- /src/Autofac/Diagnostics/OperationFailureDiagnosticData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving; 5 | 6 | namespace Autofac.Diagnostics; 7 | 8 | /// 9 | /// Diagnostic data associated with resolve operation failure events. 10 | /// 11 | public class OperationFailureDiagnosticData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The resolve operation that failed. 17 | /// The exception that caused the operation failure. 18 | public OperationFailureDiagnosticData(IResolveOperation operation, Exception operationException) 19 | { 20 | Operation = operation; 21 | OperationException = operationException; 22 | } 23 | 24 | /// 25 | /// Gets the resolve operation that failed. 26 | /// 27 | public IResolveOperation Operation { get; private set; } 28 | 29 | /// 30 | /// Gets the exception that caused the operation failure. 31 | /// 32 | public Exception OperationException { get; private set; } 33 | } 34 | -------------------------------------------------------------------------------- /src/Autofac/Diagnostics/OperationSuccessDiagnosticData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving; 5 | 6 | namespace Autofac.Diagnostics; 7 | 8 | /// 9 | /// Diagnostic data associated with resolve operation success events. 10 | /// 11 | public class OperationSuccessDiagnosticData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The resolve operation that succeeded. 17 | /// The resolved instance providing the requested service. 18 | public OperationSuccessDiagnosticData(IResolveOperation operation, object resolvedInstance) 19 | { 20 | Operation = operation; 21 | ResolvedInstance = resolvedInstance; 22 | } 23 | 24 | /// 25 | /// Gets the resolve operation that succeeded. 26 | /// 27 | public IResolveOperation Operation { get; private set; } 28 | 29 | /// 30 | /// Gets the resolved instance providing the requested service. 31 | /// 32 | public object ResolvedInstance { get; private set; } 33 | } 34 | -------------------------------------------------------------------------------- /src/Autofac/Features/LightweightAdapters/LightweightAdapterActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Features.LightweightAdapters; 7 | 8 | /// 9 | /// Describes the basic requirements for generating a lightweight adapter. 10 | /// 11 | public class LightweightAdapterActivatorData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The service that will be adapted from. 17 | /// The adapter function. 18 | public LightweightAdapterActivatorData( 19 | Service fromService, 20 | Func, object, object> adapter) 21 | { 22 | FromService = fromService; 23 | Adapter = adapter; 24 | } 25 | 26 | /// 27 | /// Gets the adapter function. 28 | /// 29 | public Func, object, object> Adapter { get; } 30 | 31 | /// 32 | /// Gets the service to be adapted from. 33 | /// 34 | public Service FromService { get; } 35 | } 36 | -------------------------------------------------------------------------------- /src/Autofac/Features/Metadata/MetaRegistrationSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Features.Metadata; 7 | 8 | /// 9 | /// Support the 10 | /// types automatically whenever type T is registered with the container. 11 | /// Metadata values come from the component registration's metadata. 12 | /// 13 | internal class MetaRegistrationSource : ImplicitRegistrationSource 14 | { 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | public MetaRegistrationSource() 19 | : base(typeof(Meta<>)) 20 | { 21 | } 22 | 23 | /// 24 | public override string Description => MetaRegistrationSourceResources.MetaRegistrationSourceDescription; 25 | 26 | /// 27 | protected override object ResolveInstance(IComponentContext ctx, in ResolveRequest request) 28 | => new Meta((T)ctx.ResolveComponent(request), request.Registration.Target.Metadata); 29 | } 30 | -------------------------------------------------------------------------------- /src/Autofac/Features/Metadata/Meta{T,TMetadata}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Features.Metadata; 5 | 6 | /// 7 | /// Provides a value along with metadata describing the value. 8 | /// 9 | /// The type of the value. 10 | /// An interface to which metadata values can be bound. 11 | public class Meta 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The value described by the instance. 17 | /// The metadata describing the value. 18 | public Meta(T value, TMetadata metadata) 19 | { 20 | Value = value; 21 | Metadata = metadata; 22 | } 23 | 24 | /// 25 | /// Gets the value described by . 26 | /// 27 | public T Value { get; } 28 | 29 | /// 30 | /// Gets metadata describing the value. 31 | /// 32 | public TMetadata Metadata { get; } 33 | } 34 | -------------------------------------------------------------------------------- /src/Autofac/Features/Metadata/Meta{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Features.Metadata; 5 | 6 | /// 7 | /// Provides a value along with a dictionary of metadata describing the value. 8 | /// 9 | /// The type of the value. 10 | public class Meta 11 | { 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The value described by the instance. 16 | /// The metadata describing the value. 17 | public Meta(T value, IDictionary metadata) 18 | { 19 | Value = value; 20 | Metadata = metadata; 21 | } 22 | 23 | /// 24 | /// Gets the value described by . 25 | /// 26 | public T Value { get; } 27 | 28 | /// 29 | /// Gets the metadata describing the value. 30 | /// 31 | public IDictionary Metadata { get; } 32 | } 33 | -------------------------------------------------------------------------------- /src/Autofac/Features/OpenGenerics/OpenGenericDelegateActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Features.OpenGenerics; 7 | 8 | /// 9 | /// Activator data for the open generic delegate activator. Holds the specified factory method. 10 | /// 11 | public class OpenGenericDelegateActivatorData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The factory method that will create a closed generic instance. 17 | public OpenGenericDelegateActivatorData(Func, object> factory) 18 | { 19 | Factory = factory ?? throw new ArgumentNullException(nameof(factory)); 20 | } 21 | 22 | /// 23 | /// Gets the factory method that will create a closed generic instance. 24 | /// 25 | public Func, object> Factory { get; } 26 | } 27 | -------------------------------------------------------------------------------- /src/Autofac/Features/OwnedInstances/InstancePerOwnedKey.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Features.OwnedInstances; 7 | 8 | /// 9 | /// Defines a key for a matching lifetime scope used by instance-per-owned. 10 | /// 11 | internal class InstancePerOwnedKey : IEquatable 12 | { 13 | private readonly TypedService _serviceWithType; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The encapsulated service. 19 | public InstancePerOwnedKey(TypedService typedService) 20 | => _serviceWithType = typedService; 21 | 22 | /// 23 | public bool Equals(IServiceWithType? other) 24 | => other is not null && _serviceWithType.ServiceType == other.ServiceType; 25 | 26 | /// 27 | public override bool Equals(object? obj) 28 | => obj is IServiceWithType serviceWithType && Equals(serviceWithType); 29 | 30 | /// 31 | public override int GetHashCode() 32 | => _serviceWithType.ServiceType.GetHashCode(); 33 | } 34 | -------------------------------------------------------------------------------- /src/Autofac/Features/Scanning/OpenGenericScanningActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Builder; 5 | 6 | namespace Autofac.Features.Scanning; 7 | 8 | /// 9 | /// Activation data for open generic types located by scanning assemblies. 10 | /// 11 | public class OpenGenericScanningActivatorData : BaseScanningActivatorData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public OpenGenericScanningActivatorData() 17 | : base(new List>>()) 18 | { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/Features/Scanning/ScanningActivatorData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Builder; 5 | 6 | namespace Autofac.Features.Scanning; 7 | 8 | /// 9 | /// Activation data for types located by scanning assemblies. 10 | /// 11 | public class ScanningActivatorData : BaseScanningActivatorData 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public ScanningActivatorData() 17 | : base(new List>>()) 18 | { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Autofac/IComponentContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | using Autofac.Core.Registration; 6 | 7 | namespace Autofac; 8 | 9 | /// 10 | /// The context in which a service can be accessed or a component's 11 | /// dependencies resolved. Disposal of a context will dispose any owned 12 | /// components. 13 | /// 14 | public interface IComponentContext 15 | { 16 | /// 17 | /// Gets the associated services with the components that provide them. 18 | /// 19 | IComponentRegistry ComponentRegistry { get; } 20 | 21 | /// 22 | /// Resolve an instance of the provided registration within the context. 23 | /// 24 | /// The resolve request. 25 | /// 26 | /// The component instance. 27 | /// 28 | /// 29 | /// 30 | object ResolveComponent(in ResolveRequest request); 31 | } 32 | -------------------------------------------------------------------------------- /src/Autofac/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Runtime.CompilerServices; 5 | using System.Runtime.InteropServices; 6 | 7 | [assembly: InternalsVisibleTo("Autofac.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001008728425885ef385e049261b18878327dfaaf0d666dea3bd2b0e4f18b33929ad4e5fbc9087e7eda3c1291d2de579206d9b4292456abffbe8be6c7060b36da0c33b883e3878eaf7c89fddf29e6e27d24588e81e86f3a22dd7b1a296b5f06fbfb500bbd7410faa7213ef4e2ce7622aefc03169b0324bcd30ccfe9ac8204e4960be6")] 8 | [assembly: CLSCompliant(false)] 9 | [assembly: ComVisible(false)] 10 | -------------------------------------------------------------------------------- /src/Autofac/PropertyWiringOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac; 5 | 6 | /// 7 | /// Options that can be applied when autowiring properties on a component. (Multiple options can 8 | /// be specified using bitwise 'or' - e.g. AllowCircularDependencies | PreserveSetValues. 9 | /// 10 | [Flags] 11 | public enum PropertyWiringOptions 12 | { 13 | /// 14 | /// Default behavior. Circular dependencies are not allowed; existing non-default 15 | /// property values are overwritten. 16 | /// 17 | None = 0, 18 | 19 | /// 20 | /// Allows property-property and property-constructor circular dependency wiring. 21 | /// This flag moves property wiring from the Activating to the Activated event. 22 | /// 23 | AllowCircularDependencies = 1, 24 | 25 | /// 26 | /// If specified, properties that already have a non-default value will be left 27 | /// unchanged in the wiring operation. 28 | /// 29 | PreserveSetValues = 2, 30 | } 31 | -------------------------------------------------------------------------------- /src/Autofac/Util/SequenceGenerator.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Util; 5 | 6 | /// 7 | /// Provides access to a unique sequenced number. 8 | /// 9 | internal static class SequenceGenerator 10 | { 11 | private static long _lastSequence; 12 | 13 | /// 14 | /// Get the next unique sequence value. 15 | /// 16 | /// A new sequence value. 17 | internal static long GetNextUniqueSequence() 18 | { 19 | while (true) 20 | { 21 | var last = Interlocked.Read(ref _lastSequence); 22 | var next = DateTime.UtcNow.Ticks; 23 | if (next <= last) 24 | { 25 | next = last + 1; 26 | } 27 | 28 | var replaced = Interlocked.CompareExchange(ref _lastSequence, next, last); 29 | if (replaced == last) 30 | { 31 | return next; 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Autofac/Util/Traverse.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Util; 5 | 6 | /// 7 | /// Provides a method to support traversing structures. 8 | /// 9 | internal static class Traverse 10 | { 11 | /// 12 | /// Traverse across a set, taking the first item in the set, and a function to determine the next item. 13 | /// 14 | /// The set type. 15 | /// The first item in the set. 16 | /// A callback that will take the current item in the set, and output the next one. 17 | /// An enumerable of the set. 18 | public static IEnumerable Across(T first, Func next) 19 | where T : class 20 | { 21 | var item = first; 22 | while (item is not null) 23 | { 24 | yield return item; 25 | item = next(item); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Autofac/Util/ValidatedNotNullAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Util; 5 | 6 | /// 7 | /// Signal attribute for static analysis that indicates a helper method is 8 | /// validating arguments for . 9 | /// 10 | [AttributeUsage(AttributeTargets.Parameter)] 11 | internal sealed class ValidatedNotNullAttribute : Attribute 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Diagnostics/DiagnosticTracerBaseTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Diagnostics; 5 | 6 | namespace Autofac.Specification.Test.Diagnostics; 7 | 8 | public class DiagnosticTracerBaseTests 9 | { 10 | [Fact] 11 | public void Enable_Disable() 12 | { 13 | var tracer = new TestTracer(); 14 | Assert.False(tracer.IsEnabled("TestEvent")); 15 | tracer.Enable("TestEvent"); 16 | Assert.True(tracer.IsEnabled("TestEvent")); 17 | tracer.Disable("TestEvent"); 18 | Assert.False(tracer.IsEnabled("TestEvent")); 19 | } 20 | 21 | private class TestTracer : DiagnosticTracerBase 22 | { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/A.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public class A : IA 7 | { 8 | public A(IC c) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/BC.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public class BC : IB, IC 7 | { 8 | public BC(IA a) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/D.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public class D : ID 7 | { 8 | public D(IA a, IC c) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/DependsByCtor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public class DependsByCtor 7 | { 8 | public DependsByCtor(DependsByProp o) 9 | { 10 | Dep = o; 11 | } 12 | 13 | public DependsByProp Dep { get; private set; } 14 | } 15 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/DependsByProp.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public class DependsByProp 7 | { 8 | public DependsByCtor Dep { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/IA.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public interface IA 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/IB.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public interface IB 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/IC.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public interface IC 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/CircularDependency/ID.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.CircularDependency; 5 | 6 | public interface ID 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/IndexTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Features.Indexed; 5 | 6 | namespace Autofac.Specification.Test.Features; 7 | 8 | public class IndexTests 9 | { 10 | [Fact] 11 | public void IndexCanRetrieveKeyedRegistration() 12 | { 13 | var key = 42; 14 | var cpt = "Hello"; 15 | var builder = new ContainerBuilder(); 16 | builder.RegisterInstance(cpt).Keyed(key); 17 | var container = builder.Build(); 18 | 19 | var idx = container.Resolve>(); 20 | Assert.Same(cpt, idx[key]); 21 | } 22 | 23 | [Fact] 24 | public void IndexComposesWithIEnumerable() 25 | { 26 | var key = 42; 27 | var cpt = "Hello"; 28 | var builder = new ContainerBuilder(); 29 | builder.RegisterInstance(cpt).Keyed(key); 30 | var container = builder.Build(); 31 | 32 | var idx = container.Resolve>>(); 33 | Assert.Same(cpt, idx[key].Single()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/MetadataTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Features.Metadata; 5 | 6 | namespace Autofac.Specification.Test.Features; 7 | 8 | public class MetadataTests 9 | { 10 | [Fact] 11 | public void WithMetadata() 12 | { 13 | var p1 = new KeyValuePair("p1", "p1Value"); 14 | var p2 = new KeyValuePair("p2", "p2Value"); 15 | 16 | var builder = new ContainerBuilder(); 17 | builder.RegisterType() 18 | .WithMetadata(p1.Key, p1.Value) 19 | .WithMetadata(p2.Key, p2.Value); 20 | 21 | var container = builder.Build(); 22 | 23 | var obj = container.Resolve>(); 24 | Assert.Contains(p1, obj.Metadata); 25 | Assert.Contains(p2, obj.Metadata); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/CtorWithValueParameter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class CtorWithValueParameter 7 | { 8 | public delegate CtorWithValueParameter Factory(string value); 9 | 10 | // The testing with this class has to do with a constructor 11 | // parameter that is named `value` - this property doesn't 12 | // need to be filled in, it just needs to exist and not be 13 | // a simple `object` or `string` or something. 14 | public HasMixedVisibilityProperties Dummy { get; set; } 15 | 16 | public CtorWithValueParameter(string value) 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasMixedVisibilityProperties.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class HasMixedVisibilityProperties 7 | { 8 | public string PublicString { get; set; } 9 | 10 | [Inject] 11 | private string PrivateString { get; set; } 12 | 13 | public string PrivateStringAccessor() 14 | { 15 | return PrivateString; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasProtectedSetterWithDefaultValue.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class HasProtectedSetterWithDefaultValue 7 | { 8 | public string Val { get; protected set; } = "Default"; 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class HasPublicSetter 7 | { 8 | public string Val { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetterDerived.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class HasPublicSetterDerived : HasPublicSetter 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasPublicSetterWithDefaultValue.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class HasPublicSetterWithDefaultValue 7 | { 8 | public string Val { get; set; } = "Default"; 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasStaticSetter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | [SuppressMessage("CA1052", "CA1052", Justification = "Handles a specific test scenario of a non-static class with a static property.")] 7 | public class HasStaticSetter 8 | { 9 | public static string Val { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/HasWriteOnlyProperty.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | public class HasWriteOnlyProperty 7 | { 8 | private string _val; 9 | 10 | [SuppressMessage("CA1044", "CA1044", Justification = "Handles a specific test case for a write-only property.")] 11 | [SuppressMessage("CA1721", "CA1721", Justification = "Handles a specific test case for a write-only property.")] 12 | public string Val 13 | { 14 | set 15 | { 16 | _val = value; 17 | } 18 | } 19 | 20 | [SuppressMessage("CA1024", "CA1024", Justification = "Handles a specific test case for a write-only property.")] 21 | public string GetVal() 22 | { 23 | return _val; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/InjectAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Features.PropertyInjection; 5 | 6 | [AttributeUsage(AttributeTargets.Property, Inherited = true)] 7 | public sealed class InjectAttribute : Attribute 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Features/PropertyInjection/InjectAttributePropertySelector.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | using Autofac.Core; 6 | 7 | namespace Autofac.Specification.Test.Features.PropertyInjection; 8 | 9 | public class InjectAttributePropertySelector : IPropertySelector 10 | { 11 | public bool InjectProperty(PropertyInfo propertyInfo, object instance) 12 | { 13 | return propertyInfo.GetCustomAttributes().Any(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Lifetime/ExternallyOwnedTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Util; 5 | 6 | namespace Autofac.Specification.Test.Lifetime; 7 | 8 | public class ExternallyOwnedTests 9 | { 10 | [Fact] 11 | public void RootInstancesNotDisposedOnContainerDisposal() 12 | { 13 | var cb = new ContainerBuilder(); 14 | cb.RegisterType().ExternallyOwned(); 15 | var c = cb.Build(); 16 | var a1 = c.Resolve(); 17 | var a2 = c.Resolve(); 18 | c.Dispose(); 19 | 20 | Assert.False(a1.IsDisposed); 21 | Assert.False(a2.IsDisposed); 22 | } 23 | 24 | private class A : DisposeTracker 25 | { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Lifetime/NestedScopeTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Lifetime; 5 | 6 | /// 7 | /// Tests involving the lifetime of a nested scope. Tests for registering objects in a nested scope are 8 | /// in . Tests for specifics 9 | /// around disposal are in or in the fixture 10 | /// for the specific lifetime model being tested (singleton, provided instance, etc.). 11 | /// 12 | public class NestedScopeTests 13 | { 14 | [Fact] 15 | public void BeginLifetimeScopeCannotBeCalledWithDuplicateTag() 16 | { 17 | var rootScope = new ContainerBuilder().Build(); 18 | const string duplicateTagName = "ABC"; 19 | var taggedScope = rootScope.BeginLifetimeScope(duplicateTagName); 20 | var differentTaggedScope = taggedScope.BeginLifetimeScope("DEF"); 21 | 22 | Assert.Throws(() => differentTaggedScope.BeginLifetimeScope(duplicateTagName)); 23 | Assert.Throws(() => differentTaggedScope.BeginLifetimeScope(duplicateTagName, builder => builder.RegisterType())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/Adapters/AnotherCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration.Adapters; 5 | 6 | public class AnotherCommand 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/Adapters/Command.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration.Adapters; 5 | 6 | public class Command 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/Adapters/IToolbarButton.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration.Adapters; 5 | 6 | public interface IToolbarButton 7 | { 8 | string Name { get; } 9 | 10 | Command Command { get; } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/Adapters/ToolbarButton.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration.Adapters; 5 | 6 | public class ToolbarButton : IToolbarButton 7 | { 8 | public ToolbarButton(Command command, string name = "") 9 | { 10 | Command = command; 11 | Name = name; 12 | } 13 | 14 | public string Name { get; } 15 | 16 | public Command Command { get; } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/AssemblyScanningPerformanceTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Diagnostics; 5 | using System.Globalization; 6 | using Xunit.Abstractions; 7 | 8 | namespace Autofac.Specification.Test.Registration; 9 | 10 | public class AssemblyScanningPerformanceTests 11 | { 12 | private readonly ITestOutputHelper _output; 13 | 14 | public AssemblyScanningPerformanceTests(ITestOutputHelper output) => _output = output; 15 | 16 | [Fact] 17 | public void MeasurePerformance() 18 | { 19 | var builder = new ContainerBuilder(); 20 | for (var i = 0; i < 1000; i++) 21 | { 22 | // Just to simulate a lot of "scanning" with few (in this case zero) "hits" 23 | builder.RegisterAssemblyTypes(GetType().Assembly).Where(x => false); 24 | } 25 | 26 | var stopwatch = Stopwatch.StartNew(); 27 | builder.Build().Dispose(); 28 | 29 | // After fix drops from ~500ms to ~100ms 30 | _output.WriteLine(stopwatch.Elapsed.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/AssemblyScanningTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | 6 | namespace Autofac.Specification.Test.Registration; 7 | 8 | public class AssemblyScanningTests 9 | { 10 | private interface IMyService 11 | { 12 | } 13 | 14 | [Fact] 15 | public void OnlyServicesAssignableToASpecificTypeAreRegisteredFromAssemblies() 16 | { 17 | var container = new ContainerBuilder().Build().BeginLifetimeScope(b => 18 | b.RegisterAssemblyTypes(GetType().GetTypeInfo().Assembly) 19 | .AssignableTo(typeof(IMyService))); 20 | 21 | Assert.Single(container.ComponentRegistry.Registrations); 22 | Assert.True(container.TryResolve(typeof(MyComponent), out object obj)); 23 | Assert.False(container.TryResolve(typeof(MyComponent2), out obj)); 24 | } 25 | 26 | private sealed class MyComponent : IMyService 27 | { 28 | } 29 | 30 | private sealed class MyComponent2 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/KeyedRegistrationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration; 5 | 6 | public class KeyedRegistrationTests 7 | { 8 | [Fact] 9 | public void TypeRegisteredWithKey() 10 | { 11 | var key = new object(); 12 | 13 | var cb = new ContainerBuilder(); 14 | cb.RegisterType().Keyed(key); 15 | 16 | var c = cb.Build(); 17 | 18 | Assert.True(c.TryResolveKeyed(key, typeof(object), out object o1)); 19 | Assert.NotNull(o1); 20 | Assert.False(c.TryResolve(typeof(object), out _)); 21 | } 22 | 23 | [Fact] 24 | public void TypeRegisteredWithName() 25 | { 26 | var name = "object.registration"; 27 | 28 | var cb = new ContainerBuilder(); 29 | cb.RegisterType().Named(name); 30 | 31 | var c = cb.Build(); 32 | 33 | Assert.True(c.TryResolveNamed(name, typeof(object), out object o1)); 34 | Assert.NotNull(o1); 35 | Assert.False(c.TryResolve(typeof(object), out _)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/LambdaRegistrationTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration; 5 | 6 | public class LambdaRegistrationTests 7 | { 8 | private interface IA 9 | { 10 | } 11 | 12 | private interface IB 13 | { 14 | } 15 | 16 | [Fact] 17 | public void RegisterLambdaAsImplementedInterfaces() 18 | { 19 | var builder = new ContainerBuilder(); 20 | builder.Register(c => new A()).AsImplementedInterfaces(); 21 | var context = builder.Build(); 22 | 23 | context.Resolve(); 24 | context.Resolve(); 25 | } 26 | 27 | [Fact] 28 | public void RegisterLambdaAsUnsupportedService() 29 | { 30 | var builder = new ContainerBuilder(); 31 | builder.Register(c => "hello").As(); 32 | Assert.Throws(() => builder.Build()); 33 | } 34 | 35 | private class A : IA, IB 36 | { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/OrderingTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration; 5 | 6 | public class OrderingTests 7 | { 8 | [Fact] 9 | public void LastInWins() 10 | { 11 | var cb = new ContainerBuilder(); 12 | var inst1 = new object(); 13 | var inst2 = new object(); 14 | cb.RegisterInstance(inst1); 15 | cb.RegisterInstance(inst2); 16 | var c = cb.Build(); 17 | Assert.Same(inst2, c.Resolve()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Registration/ParameterTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Registration; 5 | 6 | public class ParameterTests 7 | { 8 | [Fact] 9 | public void NamedParametersProvided() 10 | { 11 | var cb = new ContainerBuilder(); 12 | cb.RegisterType() 13 | .WithParameter(new NamedParameter("i", 5)) 14 | .WithParameter(new NamedParameter("j", 10)); 15 | 16 | var c = cb.Build(); 17 | var result = c.Resolve(); 18 | 19 | Assert.NotNull(result); 20 | Assert.Equal(15, result.Value); 21 | } 22 | 23 | private class WithParam 24 | { 25 | public WithParam(int i, int j) 26 | { 27 | Value = i + j; 28 | } 29 | 30 | public int Value { get; private set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/ComplexGraphTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Resolution.Graph1; 5 | 6 | namespace Autofac.Specification.Test.Resolution; 7 | 8 | public class ComplexGraphTests 9 | { 10 | [Fact] 11 | public void CanCorrectlyBuildGraph1() 12 | { 13 | var builder = new ContainerBuilder(); 14 | 15 | builder.RegisterType().SingleInstance(); 16 | builder.RegisterType().As().SingleInstance(); 17 | builder.RegisterType().SingleInstance(); 18 | builder.Register(ctr => new B1(ctr.Resolve())); 19 | 20 | var target = builder.Build(); 21 | 22 | var e = target.Resolve(); 23 | var a = target.Resolve(); 24 | var b = target.Resolve(); 25 | var c = target.Resolve(); 26 | var d = target.Resolve(); 27 | 28 | Assert.IsType(c); 29 | var cd = (CD1)c; 30 | 31 | Assert.Same(a, b.A); 32 | Assert.Same(a, cd.A); 33 | Assert.NotSame(b, cd.B); 34 | Assert.Same(c, e.C); 35 | Assert.NotSame(b, e.B); 36 | Assert.NotSame(e.B, cd.B); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/A1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Util; 5 | 6 | namespace Autofac.Specification.Test.Resolution.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class A1 : DisposeTracker 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/B1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Util; 5 | 6 | namespace Autofac.Specification.Test.Resolution.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class B1 : DisposeTracker 11 | { 12 | public B1(A1 a) 13 | { 14 | A = a; 15 | } 16 | 17 | public A1 A { get; private set; } 18 | } 19 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/C1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Util; 5 | 6 | namespace Autofac.Specification.Test.Resolution.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class C1 : DisposeTracker 11 | { 12 | public C1(B1 b) 13 | { 14 | B = b; 15 | } 16 | 17 | public B1 B { get; private set; } 18 | } 19 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/CD1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Util; 5 | 6 | namespace Autofac.Specification.Test.Resolution.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class CD1 : DisposeTracker, IC1, ID1 11 | { 12 | public CD1(A1 a, B1 b) 13 | { 14 | A = a; 15 | B = b; 16 | } 17 | 18 | public A1 A { get; private set; } 19 | 20 | public B1 B { get; private set; } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/E1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Specification.Test.Util; 5 | 6 | namespace Autofac.Specification.Test.Resolution.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class E1 : DisposeTracker 11 | { 12 | public E1(B1 b, IC1 c) 13 | { 14 | B = b; 15 | C = c; 16 | } 17 | 18 | public B1 B { get; private set; } 19 | 20 | public IC1 C { get; private set; } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/F1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Resolution.Graph1; 5 | 6 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 7 | // and E depends on IC1 and B1. 8 | public class F1 9 | { 10 | public F1(IList aList) 11 | { 12 | AList = aList; 13 | } 14 | 15 | public IList AList { get; private set; } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/GenericConstraints/A.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1.GenericConstraints; 5 | 6 | public class A : IA 7 | { 8 | public A(IB b) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/GenericConstraints/ClassWithParameterlessButNotPublicConstructor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1.GenericConstraints; 5 | 6 | public class ClassWithParameterlessButNotPublicConstructor 7 | { 8 | internal ClassWithParameterlessButNotPublicConstructor() 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/GenericConstraints/IA.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1.GenericConstraints; 5 | 6 | public interface IA 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/GenericConstraints/IB.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1.GenericConstraints; 5 | 6 | public interface IB 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/GenericConstraints/Required.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1.GenericConstraints; 5 | 6 | public class Required : IB 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/GenericConstraints/Unrelated.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1.GenericConstraints; 5 | 6 | public class Unrelated : IB 7 | where T : class, new() 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/IC1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Resolution.Graph1; 5 | 6 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 7 | // and E depends on IC1 and B1. 8 | public interface IC1 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Resolution/Graph1/ID1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Resolution.Graph1; 5 | 6 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 7 | // and E depends on IC1 and B1. 8 | public interface ID1 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Util/AsyncOnlyDisposeTracker.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Util; 5 | 6 | public class AsyncOnlyDisposeTracker : IAsyncDisposable 7 | { 8 | private readonly bool _completeAsync; 9 | 10 | public AsyncOnlyDisposeTracker(bool completeAsync = false) 11 | { 12 | _completeAsync = completeAsync; 13 | } 14 | 15 | public event EventHandler Disposing; 16 | 17 | public bool IsAsyncDisposed { get; set; } 18 | 19 | public async ValueTask DisposeAsync() 20 | { 21 | if (_completeAsync) 22 | { 23 | await Task.Delay(1); 24 | } 25 | 26 | IsAsyncDisposed = true; 27 | Disposing?.Invoke(this, EventArgs.Empty); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Autofac.Specification.Test/Util/DisposeTracker.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Specification.Test.Util; 5 | 6 | public class DisposeTracker : IDisposable 7 | { 8 | public event EventHandler Disposing; 9 | 10 | public bool IsDisposed { get; set; } 11 | 12 | protected virtual void Dispose(bool disposing) 13 | { 14 | if (disposing) 15 | { 16 | Disposing?.Invoke(this, EventArgs.Empty); 17 | } 18 | 19 | IsDisposed = true; 20 | } 21 | 22 | public void Dispose() 23 | { 24 | Dispose(true); 25 | GC.SuppressFinalize(this); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Autofac.Test.CodeGen/DelegateRegisterGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Test.CodeGen.Helpers; 5 | 6 | namespace Autofac.Test.CodeGen; 7 | 8 | public class DelegateRegisterGeneratorTests 9 | { 10 | [Fact] 11 | public Task VerifyGeneratedCode() 12 | { 13 | return CompilationVerifier.Verify(@" 14 | namespace Autofac 15 | { 16 | public static partial class RegistrationExtensions 17 | { 18 | } 19 | } 20 | "); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Autofac.Test.CodeGen/README.md: -------------------------------------------------------------------------------- 1 | # Autofac.Test.CodeGen 2 | 3 | This test project uses the [Verify](https://github.com/VerifyTests/Verify) library to perform snapshot testing of the output of our `Autofac.CodeGen` source generator. 4 | 5 | Each time the tests run, the set of generated files will be compared with the committed-to-source-control `*.verified.cs` files in the `Snapshots` folder. 6 | 7 | If any of the generated files differ from the saved `verified` file of the same name, the test will fail. 8 | 9 | When this happens a file will appear in the `Snapshots` folder with the `*.received.cs` suffix with the new file content. In Visual Studio, your IDE will also open a diff window between the two versions. 10 | 11 | > The .gitignore in the Snapshots folder exludes the received files from being saved in git, we don't want to store those. 12 | 13 | If you make changes to the generator, check that the outputted file is correct, and once you've tested the generated code, you should "accept" the new version by: 14 | 15 | - Deleting the existing `verified` file. 16 | - Renaming the new `received` file to be the `verified` one. 17 | 18 | That will then cause the tests to pass, and the new verified files should be committed to source control. 19 | -------------------------------------------------------------------------------- /test/Autofac.Test.CodeGen/Snapshots/.gitignore: -------------------------------------------------------------------------------- 1 | *.received.cs 2 | *.received.txt 3 | -------------------------------------------------------------------------------- /test/Autofac.Test.Compilation/BaseClass.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | #nullable enable 5 | 6 | namespace Autofac.Test.Compilation; 7 | 8 | public class BaseClass 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Compilation/DerivedClass.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | #nullable enable 5 | 6 | namespace Autofac.Test.Compilation; 7 | 8 | public class DerivedClass : BaseClass 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Compilation/SimpleReferenceType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | #nullable enable 5 | 6 | namespace Autofac.Test.Compilation; 7 | 8 | public class SimpleReferenceType 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.LoadContext/Autofac.Test.Scenarios.LoadContext.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0;net7.0;net6.0 4 | $(NoWarn);CS1591 5 | true 6 | false 7 | ../../build/Test.ruleset 8 | AllEnabledByDefault 9 | true 10 | false 11 | enable 12 | enable 13 | latest 14 | 15 | 16 | 17 | all 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.LoadContext/LifetimeScopeEndingModule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac; 5 | 6 | namespace A; 7 | 8 | public class LifetimeScopeEndingModule : Module 9 | { 10 | private readonly Action _invokeOnEndCallback; 11 | 12 | public LifetimeScopeEndingModule(Action invokeOnEndCallback) 13 | { 14 | _invokeOnEndCallback = invokeOnEndCallback; 15 | } 16 | 17 | protected override void Load(ContainerBuilder builder) 18 | { 19 | if (builder is null) 20 | { 21 | throw new ArgumentNullException(nameof(builder)); 22 | } 23 | 24 | builder.RegisterType(); 25 | 26 | builder.RegisterBuildCallback(scope => scope.CurrentScopeEnding += (sender, ev) => 27 | { 28 | _invokeOnEndCallback(); 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.LoadContext/OnActivatedModule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac; 5 | 6 | namespace A; 7 | 8 | public class OnActivatedModule : Module 9 | { 10 | private readonly int _value; 11 | 12 | public OnActivatedModule(int value) 13 | { 14 | _value = value; 15 | } 16 | 17 | protected override void Load(ContainerBuilder builder) 18 | { 19 | builder.RegisterType().OnActivated(x => x.Instance.Value = _value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.LoadContext/Service1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace A; 5 | 6 | public class Service1 7 | { 8 | public int Value { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/A2Component.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class A2Component : IAService, IBService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/AComponent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class AComponent 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/ADisposable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Autofac.Test.Scenarios.ScannedAssembly 7 | { 8 | public class ADisposable : IDisposable 9 | { 10 | public void Dispose() 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/AModule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class AModule : ModuleBase 7 | { 8 | protected override void Load(ContainerBuilder builder) 9 | { 10 | builder.Register(c => new AComponent()).As(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/Autofac.Test.Scenarios.ScannedAssembly.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | netstandard2.1 4 | $(NoWarn);CS1591 5 | true 6 | Autofac.Test.Scenarios.ScannedAssembly 7 | ../../Autofac.snk 8 | true 9 | Autofac.Test.Scenarios.ScannedAssembly 10 | false 11 | ../../build/Test.ruleset 12 | AllEnabledByDefault 13 | true 14 | false 15 | 16 | 17 | 18 | all 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/BComponent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class BComponent 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/BModule.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class BModule : ModuleBase 7 | { 8 | protected override void Load(ContainerBuilder builder) 9 | { 10 | builder.Register(c => new BComponent()).As(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/CloseCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class CloseCommand : ICloseCommand 7 | { 8 | public void Execute(object data) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/CommandBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | /// 7 | /// An abstract base class that implements the open generic 8 | /// interface type. 9 | /// 10 | public abstract class CommandBase : ICommand 11 | { 12 | public abstract void Execute(T data); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/DeleteCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | /// 7 | /// A command class that implements the open generic interface 8 | /// type by inheriting from the abstract base class. 9 | /// 10 | public class DeleteCommand : CommandBase 11 | { 12 | public override void Execute(DeleteCommandData data) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/DeleteCommandData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | /// 7 | /// A type to use as a generic parameter. 8 | /// 9 | public class DeleteCommandData 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/DeleteOpenGenericCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class DeleteOpenGenericCommand : CommandBase 7 | { 8 | public override void Execute(T data) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/HasDeferredEnumerable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Autofac.Test.Scenarios.ScannedAssembly 7 | { 8 | public class HasDeferredEnumerable : IHaveDeferredEnumerable 9 | { 10 | public IEnumerable Get() 11 | { 12 | yield return null; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/HasNestedFactoryDelegate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class HasNestedFactoryDelegate 7 | { 8 | public delegate HasNestedFactoryDelegate Factory(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/IAService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public interface IAService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/IBService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public interface IBService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/ICloseCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public interface ICloseCommand : ICommand 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/ICommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | /// 7 | /// An open generic interface type. 8 | /// 9 | public interface ICommand 10 | { 11 | void Execute(T data); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/IHaveDeferredEnumerable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace Autofac.Test.Scenarios.ScannedAssembly 7 | { 8 | public interface IHaveDeferredEnumerable 9 | { 10 | IEnumerable Get(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/IOpenGenericAService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public interface IOpenGenericAService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/IOpenGenericBService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public interface IOpenGenericBService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/InternalComponent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | internal class InternalComponent 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/Message.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public abstract class Message 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/DuplicatedNameAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenario 7 | { 8 | public class DuplicatedNameAttribute : Attribute, IHaveName 9 | { 10 | public DuplicatedNameAttribute(string name) 11 | { 12 | Name = name ?? throw new ArgumentNullException("name"); 13 | } 14 | 15 | public string Name { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/IHaveName.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenario 5 | { 6 | public interface IHaveName 7 | { 8 | string Name { get; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/NameAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | 6 | namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenario 7 | { 8 | public class NameAttribute : Attribute, IHaveName 9 | { 10 | public NameAttribute(string name) 11 | { 12 | Name = name ?? throw new ArgumentNullException("name"); 13 | } 14 | 15 | public string Name { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/OpenGenericScannedComponentWithMultipleNames.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenario 5 | { 6 | [Name("My Name")] 7 | [DuplicatedName("My Name 2")] 8 | public class OpenGenericScannedComponentWithMultipleNames 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/OpenGenericScannedComponentWithName.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenario 5 | { 6 | [Name("My Name")] 7 | public class OpenGenericScannedComponentWithName 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/MetadataAttributeScanningScenario/ScannedComponentWithName.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly.MetadataAttributeScanningScenario 5 | { 6 | [Name("My Name")] 7 | public class ScannedComponentWithName 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/ModuleBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public abstract class ModuleBase : Module 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/NestedComponent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class NestedComponent 7 | { 8 | private class PrivateComponent 9 | { 10 | } 11 | 12 | internal class InternalComponent 13 | { 14 | } 15 | 16 | public class PublicComponent 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/OpenGenericA2Component.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class OpenGenericA2Component : IOpenGenericAService, IOpenGenericBService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/OpenGenericAComponent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class OpenGenericAComponent 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | 6 | [assembly: AssemblyTitle("Autofac.Test.Scenarios.ScannedAssembly")] 7 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/RedoCommandData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class RedoCommandData 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/RedoOpenGenericCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class RedoOpenGenericCommand : CommandBase 7 | { 8 | public override void Execute(T data) 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/SaveCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | /// 7 | /// A command class that directly implements the open 8 | /// generic interface type. 9 | /// 10 | public class SaveCommand : ICommand 11 | { 12 | public void Execute(SaveCommandData data) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/SaveCommandData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | /// 7 | /// A type to use as a generic parameter. 8 | /// 9 | public class SaveCommandData 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/StringMessage.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class StringMessage : Message 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/UndoCommandData.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class UndoCommandData 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test.Scenarios.ScannedAssembly/UndoRedoCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ScannedAssembly 5 | { 6 | public class UndoRedoCommand : ICommand, ICommand 7 | { 8 | public void Execute(UndoCommandData data) 9 | { 10 | } 11 | 12 | public void Execute(RedoCommandData data) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Test/Builder/DeferredCallbackTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Builder; 5 | 6 | namespace Autofac.Test.Builder; 7 | 8 | public class DeferredCallbackTests 9 | { 10 | [Fact] 11 | public void Callback_Null() 12 | { 13 | var c = new DeferredCallback(reg => { }); 14 | Assert.Throws(() => { c.Callback = null; }); 15 | } 16 | 17 | [Fact] 18 | public void Ctor_NullCallback() 19 | { 20 | Assert.Throws(() => new DeferredCallback(null)); 21 | } 22 | 23 | [Fact] 24 | public void Ctor_SetsId() 25 | { 26 | var c = new DeferredCallback(reg => { }); 27 | Assert.NotEqual(Guid.Empty, c.Id); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Autofac.Test/Builder/DelegateRegistrationBuilderTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Test.Builder; 7 | 8 | public class DelegateRegistrationBuilderTests 9 | { 10 | [Fact] 11 | public void RegisterNull() 12 | { 13 | var target = new ContainerBuilder(); 14 | Assert.Throws(() => target.Register((Func)null)); 15 | } 16 | 17 | [Fact] 18 | public void ExposesImplementationType() 19 | { 20 | var cb = new ContainerBuilder(); 21 | cb.Register(c => "Hello").As(); 22 | var container = cb.Build(); 23 | Assert.True(container.ComponentRegistry.TryGetRegistration( 24 | new TypedService(typeof(object)), out IComponentRegistration cr)); 25 | Assert.Equal(typeof(string), cr.Activator.LimitType); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Autofac.Test/Builder/ProvidedInstanceRegistrationBuilderTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Test.Builder; 7 | 8 | public class ProvidedInstanceRegistrationBuilderTests 9 | { 10 | [Fact] 11 | public void LimitType_ExposesImplementationType() 12 | { 13 | var cb = new ContainerBuilder(); 14 | cb.RegisterInstance("Hello").As(); 15 | var container = cb.Build(); 16 | Assert.True(container.ComponentRegistry.TryGetRegistration( 17 | new TypedService(typeof(object)), out IComponentRegistration cr)); 18 | Assert.Equal(typeof(string), cr.Activator.LimitType); 19 | } 20 | 21 | [Fact] 22 | public void DefaultServiceType_IsStaticTypeOfRegisteredInstance() 23 | { 24 | object instance = "Hello"; 25 | 26 | var builder = new ContainerBuilder(); 27 | builder.RegisterInstance(instance); 28 | var container = builder.Build(); 29 | container.AssertRegistered(); 30 | container.AssertNotRegistered(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/Autofac.Test/CircularDependencyTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | using Autofac.Test.Scenarios.Dependencies.Circularity; 6 | 7 | namespace Autofac.Test; 8 | 9 | public class CircularDependencyTests 10 | { 11 | [Fact] 12 | public void IdentifiesCircularDependencyInExceptionMessage() 13 | { 14 | var builder = new ContainerBuilder(); 15 | builder.RegisterType().As(); 16 | builder.RegisterType().As(); 17 | builder.RegisterType().As(); 18 | var container = builder.Build(); 19 | var de = Assert.Throws(() => container.Resolve()); 20 | Assert.Contains("Autofac.Test.Scenarios.Dependencies.Circularity.D -> Autofac.Test.Scenarios.Dependencies.Circularity.A -> Autofac.Test.Scenarios.Dependencies.Circularity.BC -> Autofac.Test.Scenarios.Dependencies.Circularity.A", de.ToString(), StringComparison.Ordinal); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Autofac.Test/Core/Activators/Reflection/RecordTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | #if NET5_0_OR_GREATER 5 | 6 | namespace Autofac.Test.Core.Activators.Reflection; 7 | 8 | public class RecordTests 9 | { 10 | private record Component(IOtherService Service, IOtherService2 Service2); 11 | 12 | [Fact] 13 | public void CanResolveARecord() 14 | { 15 | var builder = new ContainerBuilder(); 16 | 17 | builder.RegisterType().As(); 18 | builder.RegisterType().As(); 19 | 20 | builder.RegisterType(); 21 | 22 | var container = builder.Build(); 23 | 24 | var record = container.Resolve(); 25 | 26 | Assert.IsType(record.Service); 27 | } 28 | 29 | private interface IOtherService 30 | { 31 | } 32 | 33 | private class OtherComponent : IOtherService 34 | { 35 | } 36 | 37 | private interface IOtherService2 38 | { 39 | } 40 | 41 | private class OtherComponent2 : IOtherService2 42 | { 43 | } 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /test/Autofac.Test/Core/ComponentRegisteredEventArgsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Test.Core; 7 | 8 | public class ComponentRegisteredEventArgsTests 9 | { 10 | [Fact] 11 | public void ConstructorSetsProperties() 12 | { 13 | using var registry = Factory.CreateEmptyComponentRegistryBuilder(); 14 | using var registration = Factory.CreateSingletonObjectRegistration(); 15 | var args = new ComponentRegisteredEventArgs(registry, registration); 16 | Assert.Same(registry, args.ComponentRegistryBuilder); 17 | Assert.Same(registration, args.ComponentRegistration); 18 | } 19 | 20 | [Fact] 21 | public void NullContainerDetected() 22 | { 23 | using var registration = Factory.CreateSingletonObjectRegistration(); 24 | Assert.Throws(() => new ComponentRegisteredEventArgs(null, registration)); 25 | } 26 | 27 | [Fact] 28 | public void NullRegistrationDetected() 29 | { 30 | using var registry = Factory.CreateEmptyComponentRegistryBuilder(); 31 | Assert.Throws(() => new ComponentRegisteredEventArgs(registry, null)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Autofac.Test/Core/PropertyInjectionInitOnlyTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | #if NET5_0_OR_GREATER 5 | 6 | namespace Autofac.Test.Core; 7 | 8 | public class PropertyInjectionInitOnlyTests 9 | { 10 | private class HasInitOnlyProperties 11 | { 12 | public string InjectedString { get; init; } 13 | } 14 | 15 | [Fact] 16 | public void CanInjectInitOnlyProperties() 17 | { 18 | var builder = new ContainerBuilder(); 19 | builder.RegisterType().PropertiesAutowired(); 20 | builder.Register(context => "hello world"); 21 | var container = builder.Build(); 22 | 23 | var instance = container.Resolve(); 24 | 25 | Assert.Equal("hello world", instance.InjectedString); 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /test/Autofac.Test/Core/Registration/ComponentRegistrationLifetimeDecoratorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Lifetime; 5 | using Autofac.Core.Registration; 6 | 7 | namespace Autofac.Test.Core.Registration; 8 | 9 | public class ComponentRegistrationLifetimeDecoratorTests 10 | { 11 | [Fact] 12 | public void DecoratorCallsDisposeOnInnerInstance() 13 | { 14 | using var inner = Mocks.GetComponentRegistration(); 15 | var decorator = new ComponentRegistrationLifetimeDecorator(inner, CurrentScopeLifetime.Instance); 16 | 17 | decorator.Dispose(); 18 | 19 | Assert.True(inner.IsDisposed); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Test/Core/Resolving/CircularDependencyDetectorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Test.Core.Resolving; 7 | 8 | public class CircularDependencyDetectorTests 9 | { 10 | [Fact] 11 | public void OnCircularDependency_MessageDescribesCycle() 12 | { 13 | var builder = new ContainerBuilder(); 14 | builder.Register(c => c.Resolve()); 15 | 16 | var target = builder.Build(); 17 | var de = Assert.Throws(() => target.Resolve()); 18 | Assert.Contains("λ:System.Object -> λ:System.Object", de.ToString(), StringComparison.Ordinal); 19 | Assert.DoesNotContain("λ:System.Object -> λ:System.Object -> λ:System.Object", de.Message, StringComparison.Ordinal); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Test/Core/Resolving/Middleware/CircularDependencyMiddlewareTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core.Resolving.Middleware; 5 | using Autofac.Core.Resolving.Pipeline; 6 | 7 | namespace Autofac.Test.Core.Resolving; 8 | 9 | public class CircularDependencyMiddlewareTests 10 | { 11 | [Fact] 12 | public void NextCalled_OperationIsNotIDependencyTrackingResolveOperation_MiddlewareSkipped() 13 | { 14 | var resolveRequestContextMock = Substitute.For(); 15 | var middleware = 16 | new CircularDependencyDetectorMiddleware(CircularDependencyDetectorMiddleware.DefaultMaxResolveDepth); 17 | 18 | middleware.Execute(resolveRequestContextMock, context => { }); 19 | 20 | resolveRequestContextMock.Received(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/LazyDependencies/LazyWithMetadata_WhenNoMatchingMetadataIsSupplied.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | using Autofac.Test.Features.Metadata.TestTypes; 6 | 7 | namespace Autofac.Test.Features.LazyDependencies; 8 | 9 | public class LazyWithMetadata_WhenNoMatchingMetadataIsSupplied 10 | { 11 | private readonly IContainer _container; 12 | 13 | public LazyWithMetadata_WhenNoMatchingMetadataIsSupplied() 14 | { 15 | var builder = new ContainerBuilder(); 16 | builder.RegisterType(); 17 | _container = builder.Build(); 18 | } 19 | 20 | [Fact] 21 | public void ResolvingStronglyTypedMetadataWithoutDefaultValueThrowsException() 22 | { 23 | Assert.Throws(() => _container.Resolve>()); 24 | } 25 | 26 | [Fact] 27 | public void ResolvingStronglyTypedMetadataWithDefaultValueProvidesDefault() 28 | { 29 | var m = _container.Resolve>(); 30 | Assert.Equal(42, m.Metadata.TheInt); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/MetaRegistrationSourceTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Features.Metadata; 5 | 6 | namespace Autofac.Test.Features.Metadata; 7 | 8 | public class MetaRegistrationSourceTests 9 | { 10 | [Fact] 11 | public void WhenGeneratingMetadata_ValuesProvidedFromMetadata() 12 | { 13 | var builder = new ContainerBuilder(); 14 | builder.RegisterType().WithMetadata("TheInt", 42); 15 | var container = builder.Build(); 16 | var meta = container.Resolve>(); 17 | Assert.Equal(42, meta.Metadata["TheInt"]); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/TestTypes/IMyMetaInterface.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Features.Metadata.TestTypes; 5 | 6 | public interface IMyMetaInterface 7 | { 8 | int TheInt { get; } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/TestTypes/MyMeta.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Features.Metadata.TestTypes; 5 | 6 | public class MyMeta 7 | { 8 | public int TheInt { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDefault.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.ComponentModel; 5 | 6 | namespace Autofac.Test.Features.Metadata.TestTypes; 7 | 8 | public class MyMetaWithDefault 9 | { 10 | [DefaultValue(42)] 11 | public int TheInt { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithDictionary.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Features.Metadata.TestTypes; 5 | 6 | [SuppressMessage("CA1711", "CA1711", Justification = "Naming helps clarify the purpose of the object for test consumers.")] 7 | public class MyMetaWithDictionary 8 | { 9 | public MyMetaWithDictionary(IDictionary metadata) 10 | { 11 | ArgumentNullException.ThrowIfNull(metadata); 12 | TheName = (string)metadata["Name"]; 13 | } 14 | 15 | public string TheName { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithInvalidConstructor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Features.Metadata.TestTypes; 5 | 6 | public class MyMetaWithInvalidConstructor 7 | { 8 | public MyMetaWithInvalidConstructor(string unsupported) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/Metadata/TestTypes/MyMetaWithReadOnlyProperty.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Features.Metadata.TestTypes; 5 | 6 | public class MyMetaWithReadOnlyProperty 7 | { 8 | public int TheInt { get; set; } 9 | 10 | public string ReadOnly 11 | { 12 | get 13 | { 14 | return "Foo"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OpenGenerics/ComplexGenericScenarios/CompanyA/CompositeValidator{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace CompanyA; 5 | 6 | internal class CompositeValidator : FluentValidation.AbstractValidator, IValidator 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OpenGenerics/ComplexGenericScenarios/CompanyA/IValidator{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace CompanyA; 5 | 6 | // Please note that this name is the same as FluentValidation's IValidator 7 | internal interface IValidator 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OpenGenerics/ComplexGenericScenarios/CompanyB/CompositeValidator{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace CompanyB; 5 | 6 | internal class CompositeValidator : FluentValidation.AbstractValidator, IValidatorSomeOtherName 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OpenGenerics/ComplexGenericScenarios/CompanyB/IValidatorSomeOtherName{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace CompanyB; 5 | 6 | // Please note that this name is NOT the same as FluentValidation's IValidator 7 | internal interface IValidatorSomeOtherName 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OpenGenerics/ComplexGenericScenarios/FluentValidation/AbstractValidator{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace FluentValidation; 5 | 6 | internal class AbstractValidator : IValidator 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OpenGenerics/ComplexGenericScenarios/FluentValidation/IValidator{T}.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace FluentValidation; 5 | 6 | internal interface IValidator 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Features/OwnedInstances/InstancePerOwnedKeyTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | using Autofac.Features.OwnedInstances; 6 | 7 | namespace Autofac.Test.Features.OwnedInstances; 8 | 9 | public class InstancePerOwnedKeyTests 10 | { 11 | [Theory] 12 | [InlineData(typeof(string), "Foo", typeof(string), true)] 13 | [InlineData(typeof(string), null, typeof(string), true)] 14 | [InlineData(typeof(string), "Foo", typeof(int), false)] 15 | [InlineData(typeof(string), null, typeof(int), false)] 16 | [InlineData(typeof(int), "Foo", typeof(string), false)] 17 | [InlineData(typeof(int), null, typeof(string), false)] 18 | public void ServiceEquality(Type dependencyType, object ownedKey, Type ownedType, bool expected) 19 | { 20 | var dependencyService = new TypedService(dependencyType); 21 | var instancePerOwnedKey = new InstancePerOwnedKey(dependencyService); 22 | 23 | var ownedService = ownedKey is not null 24 | ? (IServiceWithType)new KeyedService(ownedKey, ownedType) 25 | : new TypedService(ownedType); 26 | 27 | Assert.Equal(expected, instancePerOwnedKey.Equals(ownedService)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Adapters/AnotherCommand.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Adapters; 5 | 6 | public class AnotherCommand 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Adapters/Command.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Adapters; 5 | 6 | public class Command 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Adapters/IToolbarButton.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Adapters; 5 | 6 | public interface IToolbarButton 7 | { 8 | string Name { get; } 9 | 10 | Command Command { get; } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Adapters/ToolbarButton.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Adapters; 5 | 6 | public class ToolbarButton : IToolbarButton 7 | { 8 | public ToolbarButton(Command command, string name = "") 9 | { 10 | Command = command; 11 | Name = name; 12 | } 13 | 14 | public string Name { get; } 15 | 16 | public Command Command { get; } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/ConstructorSelection/MultipleConstructors.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.ConstructorSelection; 5 | 6 | public class MultipleConstructors 7 | { 8 | public MultipleConstructors(object o, string s) 9 | { 10 | } 11 | 12 | public MultipleConstructors(object o) 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/A.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public class A : IA 7 | { 8 | public A(IC c) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/BC.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public class BC : IB, IC 7 | { 8 | public BC(IA a) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/D.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public class D : ID 7 | { 8 | public D(IA a, IC c) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/IA.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public interface IA 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/IB.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public interface IB 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/IC.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public interface IC 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Circularity/ID.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies.Circularity; 5 | 6 | public interface ID 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/Dependent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies; 5 | 6 | public class Dependent 7 | { 8 | public object TheObject { get; private set; } 9 | 10 | public string TheString { get; private set; } 11 | 12 | public Dependent(object o, string s) 13 | { 14 | TheObject = o; 15 | TheString = s; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/DependsByCtor.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies; 5 | 6 | public class DependsByCtor 7 | { 8 | public DependsByCtor(DependsByProp o) 9 | { 10 | Dep = o; 11 | } 12 | 13 | public DependsByProp Dep { get; private set; } 14 | } 15 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Dependencies/DependsByProp.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Dependencies; 5 | 6 | public class DependsByProp 7 | { 8 | public DependsByCtor Dep { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/A1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Test.Util; 5 | 6 | namespace Autofac.Test.Scenarios.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class A1 : DisposeTracker 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/B1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Test.Util; 5 | 6 | namespace Autofac.Test.Scenarios.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class B1 : DisposeTracker 11 | { 12 | public B1(A1 a) 13 | { 14 | A = a; 15 | } 16 | 17 | public A1 A { get; private set; } 18 | } 19 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/C1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Test.Util; 5 | 6 | namespace Autofac.Test.Scenarios.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class C1 : DisposeTracker 11 | { 12 | public C1(B1 b) 13 | { 14 | B = b; 15 | } 16 | 17 | public B1 B { get; private set; } 18 | } 19 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/CD1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Test.Util; 5 | 6 | namespace Autofac.Test.Scenarios.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class CD1 : DisposeTracker, IC1, ID1 11 | { 12 | public CD1(A1 a, B1 b) 13 | { 14 | A = a; 15 | B = b; 16 | } 17 | 18 | public A1 A { get; private set; } 19 | 20 | public B1 B { get; private set; } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/E1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Test.Util; 5 | 6 | namespace Autofac.Test.Scenarios.Graph1; 7 | 8 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 9 | // and E depends on IC1 and B1. 10 | public class E1 : DisposeTracker 11 | { 12 | public E1(B1 b, IC1 c) 13 | { 14 | B = b; 15 | C = c; 16 | } 17 | 18 | public B1 B { get; private set; } 19 | 20 | public IC1 C { get; private set; } 21 | } 22 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/F1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1; 5 | 6 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 7 | // and E depends on IC1 and B1. 8 | public class F1 9 | { 10 | public IList AList { get; private set; } 11 | 12 | public F1(IList aList) 13 | { 14 | AList = aList; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/IC1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1; 5 | 6 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 7 | // and E depends on IC1 and B1. 8 | public interface IC1 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Graph1/ID1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Graph1; 5 | 6 | // In the below scenario, B1 depends on A1, CD depends on A1 and B1, 7 | // and E depends on IC1 and B1. 8 | public interface ID1 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/Parameterization/Parameterized.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.Parameterization; 5 | 6 | public class Parameterized 7 | { 8 | public string A { get; private set; } 9 | 10 | public int B { get; private set; } 11 | 12 | public Parameterized(string a, int b) 13 | { 14 | A = a; 15 | B = b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/RegistrationSources/ObjectRegistrationSource.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Core; 5 | 6 | namespace Autofac.Test.Scenarios.RegistrationSources; 7 | 8 | public class ObjectRegistrationSource : IRegistrationSource 9 | { 10 | private readonly object _instance; 11 | 12 | public ObjectRegistrationSource() 13 | : this(new object()) 14 | { 15 | } 16 | 17 | public ObjectRegistrationSource(object instance) 18 | { 19 | _instance = instance; 20 | } 21 | 22 | public IEnumerable RegistrationsFor(Service service, Func> registrationAccessor) 23 | { 24 | var objectService = new TypedService(typeof(object)); 25 | if (service == objectService) 26 | { 27 | yield return Factory.CreateSingletonObjectRegistration(_instance); 28 | } 29 | } 30 | 31 | public bool IsAdapterForIndividualComponents 32 | { 33 | get { return false; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/Autofac.Test/Scenarios/WithProperty/WithProps.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Scenarios.WithProperty; 5 | 6 | public class WithProps 7 | { 8 | public string A { get; set; } 9 | 10 | public bool B { get; set; } 11 | 12 | [SuppressMessage("SA1401", "SA1401", Justification = "Public field handles a specific test case.")] 13 | [SuppressMessage("CA1051", "CA1051", Justification = "Public field handles a specific test case.")] 14 | public string _field; 15 | } 16 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/AsyncDisposeTracker.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Util; 5 | 6 | public sealed class AsyncDisposeTracker : IDisposable, IAsyncDisposable 7 | { 8 | private readonly SemaphoreSlim _semaphore; 9 | 10 | public event EventHandler Disposing; 11 | 12 | public bool IsSyncDisposed { get; set; } 13 | 14 | public bool IsAsyncDisposed { get; set; } 15 | 16 | public AsyncDisposeTracker() 17 | : this(null) 18 | { 19 | } 20 | 21 | public AsyncDisposeTracker(SemaphoreSlim semaphore) 22 | { 23 | _semaphore = semaphore; 24 | } 25 | 26 | public void Dispose() 27 | { 28 | IsSyncDisposed = true; 29 | 30 | Disposing?.Invoke(this, EventArgs.Empty); 31 | } 32 | 33 | public async ValueTask DisposeAsync() 34 | { 35 | if (_semaphore != null) 36 | { 37 | await _semaphore.WaitAsync(); 38 | } 39 | 40 | try 41 | { 42 | IsAsyncDisposed = true; 43 | 44 | Disposing?.Invoke(this, EventArgs.Empty); 45 | } 46 | finally 47 | { 48 | _semaphore?.Release(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/AsyncOnlyDisposeTracker.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Util; 5 | 6 | public class AsyncOnlyDisposeTracker : IAsyncDisposable 7 | { 8 | public event EventHandler Disposing; 9 | 10 | public bool IsAsyncDisposed { get; set; } 11 | 12 | public async ValueTask DisposeAsync() 13 | { 14 | await Task.Delay(1); 15 | 16 | IsAsyncDisposed = true; 17 | 18 | Disposing?.Invoke(this, EventArgs.Empty); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/Cache/ReflectionCacheAssemblyDictionaryTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using System.Reflection; 5 | using Autofac.Util.Cache; 6 | 7 | namespace Autofac.Test.Util.Cache; 8 | 9 | public class ReflectionCacheAssemblyDictionaryTests 10 | { 11 | [Fact] 12 | public void CanClearContents() 13 | { 14 | var cacheDict = new ReflectionCacheAssemblyDictionary(); 15 | 16 | cacheDict[typeof(string).Assembly] = false; 17 | 18 | cacheDict.Clear(); 19 | 20 | Assert.Empty(cacheDict); 21 | } 22 | 23 | [Fact] 24 | public void CanConditionallyClearContents() 25 | { 26 | var cacheDict = new ReflectionCacheAssemblyDictionary(); 27 | 28 | cacheDict[typeof(string).Assembly] = false; 29 | cacheDict[typeof(ContainerBuilder).Assembly] = false; 30 | 31 | cacheDict.Clear((member, assemblies) => 32 | { 33 | Assert.Null(member); 34 | 35 | return assemblies.Contains(typeof(string).Assembly); 36 | }); 37 | 38 | Assert.Collection(cacheDict, (kvp) => Assert.Equal(typeof(ContainerBuilder).Assembly, kvp.Key)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/DelegateExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Util; 5 | 6 | namespace Autofac.Test.Util; 7 | 8 | public class DelegateExtensionsTests 9 | { 10 | private class WithTwoInvokes 11 | { 12 | public void Invoke() 13 | { 14 | } 15 | 16 | public void Invoke(string s) 17 | { 18 | } 19 | } 20 | 21 | // Issue 179 22 | [Fact] 23 | public void TypeWithTwoInvokeMethodsIsNotADelegate() 24 | { 25 | Assert.False(typeof(WithTwoInvokes).IsDelegate()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/DisposeTracker.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | namespace Autofac.Test.Util; 5 | 6 | public class DisposeTracker : IDisposable 7 | { 8 | public event EventHandler Disposing; 9 | 10 | public bool IsDisposed { get; set; } 11 | 12 | protected virtual void Dispose(bool disposing) 13 | { 14 | if (disposing) 15 | { 16 | Disposing?.Invoke(this, EventArgs.Empty); 17 | } 18 | 19 | IsDisposed = true; 20 | } 21 | 22 | public void Dispose() 23 | { 24 | Dispose(true); 25 | GC.SuppressFinalize(this); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/EnforceTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Util; 5 | 6 | namespace Autofac.Test.Util; 7 | 8 | public class EnforceTests 9 | { 10 | [Fact] 11 | public void FindsEmptyElementInList() 12 | { 13 | Assert.Throws(() => 14 | Enforce.ArgumentElementNotNull(new object[] { null }, "arg")); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/Autofac.Test/Util/SequenceGeneratorTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Autofac Project. All rights reserved. 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. 3 | 4 | using Autofac.Util; 5 | 6 | namespace Autofac.Test.Util; 7 | 8 | public class SequenceGeneratorTests 9 | { 10 | [Fact] 11 | public void AlwaysGeneratesUniqueAscendingSequenceNumbers() 12 | { 13 | var last = 0L; 14 | var next = SequenceGenerator.GetNextUniqueSequence(); 15 | 16 | for (var i = 0; i < 100000; i++) 17 | { 18 | Assert.True(next > last); 19 | last = next; 20 | next = SequenceGenerator.GetNextUniqueSequence(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Test Projects 2 | 3 | - `Autofac.Test` is for unit tests that likely access internals to check on boundary conditions and so on. As versions of Autofac change and grow, these may also change and grow. 4 | - `Autofac.Specification.Test` is for tests that access Autofac through the more standard public API - doing register and resolve calls, passing in parameters, that sort of thing. In general, if the "average user" wouldn't do it (e.g., follow the interfaces all the way down to count things like how many registration sources are there) or if it accesses internals, it shouldn't be there. This test suite is intended to stay pretty stable so we can ensure the 90% case is still working if we refactor internals and possibly make breaking changes. 5 | -------------------------------------------------------------------------------- /test/Shims/required/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | # dont complain about .NET Foundation license header 3 | dotnet_diagnostic.SA1636.severity = none 4 | # dont enforce documentation styles for imported shims 5 | dotnet_diagnostic.SA1623.severity = none 6 | # dont enforce coding styles for imported shims 7 | dotnet_diagnostic.SA1502.severity = none 8 | -------------------------------------------------------------------------------- /test/Shims/required/README.md: -------------------------------------------------------------------------------- 1 | # Shim Files for the `required` Feature 2 | 3 | Functional polyfill copied from to allow use of `required` keyword in frameworks below .NET7 (if `LangVersion`is set high enough to offer that feature.) 4 | 5 | - [SetsRequiredMemberAttribute.cs](https://github.com/dotnet/runtime/blob/c1ab6c5b2524880ed9368841a0a5d8ead78ea09d/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/SetsRequiredMembersAttribute.cs) 6 | - [RequiredMemberAttribute.cs](https://github.com/dotnet/runtime/blob/c1ab6c5b2524880ed9368841a0a5d8ead78ea09d/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RequiredMemberAttribute.cs) 7 | - [CompilerFeatureRequiredAttribute.cs](https://github.com/dotnet/runtime/blob/c1ab6c5b2524880ed9368841a0a5d8ead78ea09d/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CompilerFeatureRequiredAttribute.cs) 8 | -------------------------------------------------------------------------------- /test/Shims/required/RequiredMemberAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | #if !NET7_0_OR_GREATER 5 | 6 | using System.ComponentModel; 7 | 8 | namespace System.Runtime.CompilerServices 9 | { 10 | /// Specifies that a type has required members or that a member is required. 11 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] 12 | [EditorBrowsable(EditorBrowsableState.Never)] 13 | #if SYSTEM_PRIVATE_CORELIB 14 | public 15 | #else 16 | internal 17 | #endif 18 | sealed class RequiredMemberAttribute : Attribute 19 | { } 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /test/Shims/required/SetsRequiredMembersAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | #if !NET7_0_OR_GREATER 5 | 6 | namespace System.Diagnostics.CodeAnalysis 7 | { 8 | /// 9 | /// Specifies that this constructor sets all required members for the current type, and callers 10 | /// do not need to set any required members themselves. 11 | /// 12 | [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] 13 | #if SYSTEM_PRIVATE_CORELIB 14 | public 15 | #else 16 | internal 17 | #endif 18 | sealed class SetsRequiredMembersAttribute : Attribute 19 | { } 20 | } 21 | 22 | #endif 23 | --------------------------------------------------------------------------------