Lifetime scope implementation.
Inheritance: Disposable, ISharingLifetimeScope, IServiceProvider
示例#1
0
        /// <summary>
        /// Create a new container.
        /// </summary>
        internal Container()
        {
            _componentRegistry = new ComponentRegistry();

            _componentRegistry.Register(new ComponentRegistration(
                LifetimeScope.SelfRegistrationId,
                new DelegateActivator(typeof(LifetimeScope), (c, p) =>
                {
                    throw new InvalidOperationException("The container's self-registration of context interfaces should never be activated as it is hard-wired into the LifetimeScope class.");
                }),
                new CurrentScopeLifetime(),
                InstanceSharing.Shared,
                InstanceOwnership.ExternallyOwned,
                new Service[] { new TypedService(typeof(ILifetimeScope)), new TypedService(typeof(IComponentContext)) },
                new Dictionary<string, object>()));

            _rootLifetimeScope = new LifetimeScope(_componentRegistry);
        }
示例#2
0
		/// <summary>
		/// Create a new container.
		/// </summary>
		internal Container()
		{
			_componentRegistry = new ComponentRegistry();

			_componentRegistry.Register(new ComponentRegistration(
				LifetimeScope.SelfRegistrationId,
				new DelegateActivator(typeof(LifetimeScope), (c, p) =>
				{
					throw new InvalidOperationException(ContainerResources.SelfRegistrationCannotBeActivated);
				}),
				new CurrentScopeLifetime(),
				InstanceSharing.Shared,
				InstanceOwnership.ExternallyOwned,
				new Service[] { new TypedService(typeof(ILifetimeScope)), new TypedService(typeof(IComponentContext)) },
				new Dictionary<string, object>()));

			_rootLifetimeScope = new LifetimeScope(_componentRegistry);
		}
示例#3
0
 /// <summary>
 /// Create a lifetime scope for the provided components and nested beneath a parent.
 /// </summary>
 /// <param name="tag">The tag applied to the <see cref="ILifetimeScope"/>.</param>
 /// <param name="componentRegistry">Components used in the scope.</param>
 /// <param name="parent">Parent scope.</param>
 protected LifetimeScope(IComponentRegistry componentRegistry, LifetimeScope parent, object tag)
     : this(componentRegistry, tag)
 {
     _parent = Enforce.ArgumentNotNull(parent, "parent");
     _root   = _parent.RootLifetimeScope;
 }
示例#4
0
		/// <summary>
		/// Create a lifetime scope for the provided components and nested beneath a parent.
		/// </summary>
		/// <param name="tag">The tag applied to the <see cref="ILifetimeScope"/>.</param>
		/// <param name="componentRegistry">Components used in the scope.</param>
		/// <param name="parent">Parent scope.</param>
		protected LifetimeScope(IComponentRegistry componentRegistry, LifetimeScope parent, object tag)
			: this(componentRegistry, tag)
		{
			_parent = Enforce.ArgumentNotNull(parent, "parent");
			_root = _parent.RootLifetimeScope;
		}
示例#5
0
		/// <summary>
		/// Begin a new tagged sub-scope. Instances created via the sub-scope
		/// will be disposed along with it.
		/// </summary>
		/// <param name="tag">The tag applied to the <see cref="ILifetimeScope"/>.</param>
		/// <returns>A new lifetime scope.</returns>
		public ILifetimeScope BeginLifetimeScope(object tag)
		{
			CheckNotDisposed();
			var registry = new CopyOnWriteRegistry(_componentRegistry, () => CreateScopeRestrictedRegistry(tag, NoConfiguration));
			var scope = new LifetimeScope(registry, this, tag);
			return scope;
		}