├── .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