/// <summary> /// Creates a new service scope. /// </summary> /// <returns> /// A new service scope. /// </returns> /// <exception cref="CreateDependencyScopeException"> /// An exception was raised while attempting to create the scope. /// </exception> public IServiceScope CreateScope() { try { return(new ServiceScope(DependencyScope.CreateChildScope())); } catch (ObjectDisposedException exception) { throw new CreateDependencyScopeException(exception); } }
/// <summary> /// Releases all resources consumed by the current <see cref="ServiceScope" />. /// </summary> /// <param name="disposing"> /// A value indicating whether or not managed resources should be released. /// </param> protected override void Dispose(Boolean disposing) { try { if (disposing) { DependencyScope.Dispose(); } } finally { base.Dispose(disposing); } }
/// <summary> /// Initializes a new instance of the <see cref="ServiceScope" /> class. /// </summary> /// <param name="dependencyScope"> /// The scope that is abstracted by the service scope. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="dependencyScope" /> is <see langword="null" />. /// </exception> public ServiceScope(IDependencyScope dependencyScope) { DependencyScope = dependencyScope.RejectIf().IsNull(nameof(dependencyScope)).TargetArgument; LazyProvider = new Lazy <IServiceProvider>(() => DependencyScope.Resolve <IServiceProvider>(), LazyThreadSafetyMode.ExecutionAndPublication); }