/// <summary> /// Creates a new scope manager instance using the specified parent /// service container and the related singleton manager. /// </summary> /// <param name="rootServiceProvider">The parent container that is shared by the nested containers that are to be managed.</param> /// <param name="singletonManager">The singleton manager managing the singleton services for the nested containers. Must not be <see langword="null"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="singletonManager"/> is <see langword="null"/>.</exception> public NestedScopedServicesManager( IServiceProvider rootServiceProvider, NestedSingletonServicesManager <TFamily, TKey> singletonManager) { var keyComparer = NestingKeyComparer <TKey> . GetNestingKeyComparer(rootServiceProvider); serviceScopes = new Dictionary <TKey, WeakReference <IServiceScope> >(keyComparer); this.singletonManager = singletonManager.ThrowIfNull(nameof(singletonManager)); }
/// <summary> /// Creates a new nested singleton manager instance using the specified /// parent service container and the nested service collections. /// </summary> /// <param name="rootServiceProvider">The parent container that is shared by the nested containers that are to be managed.</param> /// <param name="nestedServices">The nested service collections that have been registered for the specified root service provider. Must not be <see langword="null"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="nestedServices"/> is <see langword="null"/>.</exception> public NestedSingletonServicesManager(IServiceProvider rootServiceProvider, IEnumerable <INestedServiceCollection <TFamily, TKey> > nestedServices) { this.rootServiceProvider = rootServiceProvider; IEqualityComparer <TKey> keyComparer = NestingKeyComparer <TKey> . GetNestingKeyComparer(rootServiceProvider); this.nestedServices = nestedServices .ThrowIfNull(nameof(nestedServices)) .ToDictionary( nsc => nsc.Key, nsc => nsc as IServiceCollection, keyComparer ); nestedServiceProviders = new Dictionary <TKey, WeakReference <IServiceProvider> >( keyComparer); }