Example #1
0
 protected override void Dispose(bool explicitDispose)
 {
     if (explicitDispose)
     {
         _newDependencyInstancesDisposeRegistry?.Dispose();
         //
         _runningResolutionsSpinLock?.EnterAndExitLock();
         _runningResolutionsUniqueness?.Clear();
         _runningResolutionsSequence?.Clear();
         //
         _resolutionModelLazy?.Dispose();
         //
         _exporter?.Dispose();
         //
         _outerScopeGetter?.Dispose();
     }
     _newDependencyInstancesDisposeRegistry = null;
     _runningResolutionsUniqueness          = null;
     _runningResolutionsSequence            = null;
     _runningResolutionsSpinLock            = null;
     _resolutionModelLazy = null;
     _exporter            = null;
     _outerScopeGetter    = null;
     _serviceProviderApi  = null;
     _owner = null;
     //
     base.Dispose(explicitDispose);
 }
Example #2
0
 // TODO: Put strings into the resources.
 //
 public DependencyResolutionSpecs(
     Type dependencyType,
     bool ensureResolution                                = false,
     bool isNewInstanceRequired                           = false,
     IArgsTuple newInstanceFactoryArgs                    = null,
     bool preventNewInstanceInitialization                = false,
     IDependencyResolutionModel primaryResolutionModel    = null,
     IDependencyResolutionSelectCriterion selectCriterion = null,
     IDisposeRegistry disposeRegistry                     = null)
 {
     //
     dependencyType.EnsureNotNull(nameof(dependencyType));
     if (!isNewInstanceRequired && newInstanceFactoryArgs != null)
     {
         throw
             new ArgumentException(
                 message: $"Этот аргумент не применим и должен иметь значение '{((object)null).FmtStr().G()}', когда значение аргумента '{nameof(isNewInstanceRequired)}' равно '{false.FmtStr().G()}'.",
                 paramName: nameof(newInstanceFactoryArgs));
     }
     //
     _dependencyType                   = dependencyType;
     _ensureResolution                 = ensureResolution;
     _isNewInstanceRequired            = isNewInstanceRequired;
     _newInstanceFactoryArgs           = newInstanceFactoryArgs;
     _preventNewInstanceInitialization = preventNewInstanceInitialization;
     _primaryResolutionModel           = primaryResolutionModel;
     _selectCriterion                  = selectCriterion;
     _disposeRegistry                  = disposeRegistry;
 }
Example #3
0
 protected override void Dispose(bool explicitDispose)
 {
     _dependencyType         = null;
     _primaryResolutionModel = null;
     _selectCriterion        = null;
     _newInstanceFactoryArgs = null;
     _disposeRegistry        = null;
     //
     base.Dispose(explicitDispose);
 }
Example #4
0
 void P_CtorInitializer(IDependencyExporter exporter, bool ownsDependencyExporter = default, IServiceProvider outerServiceProvider = default, object owner = default)
 {
     exporter.EnsureNotNull(nameof(exporter));
     //
     _exporter = exporter.ToValueHolder(ownsDependencyExporter);
     _owner    = owner;
     //
     _resolutionModelLazy =
         new DisposableLazy <IDependencyResolutionModel <DependencyScope> >(
             factory: () => new DependencyResolutionModel <DependencyScope>(scope: this, handlerChainSource: ReadDA(ref _exporter, considerDisposeRequest: true).Value.ExportDependencies()),
             ownsValue: true);
     //
     _newDependencyInstancesDisposeRegistry = new DisposeRegistry();
     //
     _runningResolutionsSpinLock   = new PrimitiveSpinLock();
     _runningResolutionsUniqueness = new HashSet <IDependencyResolutionContext>(comparer: ReferenceEqualityComparer <IDependencyResolutionContext> .Instance);
     _runningResolutionsSequence   = new List <IDependencyResolutionContext>();
     //
     _serviceProviderApi = outerServiceProvider ?? new P_ServiceProviderApi(scope: this);
 }
 public DependencyResolutionSpecs(
     Type dependencyTypeConstraint                     = null,
     bool ensureResolution                             = false,
     bool isNewInstanceRequired                        = false,
     IArgsTuple newInstanceFactoryArgs                 = null,
     bool preventNewInstanceInitialization             = false,
     IDependencyResolutionModel primaryResolutionModel = null,
     IDependencyResolutionSelectCriterion <TDependency> selectCriterion = null,
     IDisposeRegistry disposeRegistry = null)
     : base(
         dependencyType: dependencyTypeConstraint.Arg(nameof(dependencyTypeConstraint)).EnsureCompatible(__DependencyType).Value ?? __DependencyType,
         ensureResolution: ensureResolution,
         isNewInstanceRequired: isNewInstanceRequired,
         newInstanceFactoryArgs: newInstanceFactoryArgs,
         preventNewInstanceInitialization: preventNewInstanceInitialization,
         primaryResolutionModel: primaryResolutionModel,
         selectCriterion: selectCriterion,
         disposeRegistry: disposeRegistry)
 {
     _selectCriterion = selectCriterion;
 }