/// <summary> /// Constructs a new instance of the <see cref="Container"/> class. /// </summary> /// <param name="targets">Optional. The target container whose registrations will be used for dependency lookup when /// <see cref="Resolve(ResolveContext)"/> (and other operations) is called. If not provided, a new /// <see cref="TargetContainer"/> instance is constructed. This will ultimately be available /// to derived types, after construction, through the <see cref="Targets"/> property.</param> /// <param name="config">Can be null. Configuration to apply to this container (and, potentially its <see cref="Targets"/>). /// If not provided, then the <see cref="DefaultConfig"/> will be used.</param> /// <remarks>Note to inheritors - this constructor throws an <see cref="InvalidOperationException"/> if used by a derived class, /// because the application of configuration to the container will likely cause virtual methods to be called. Instead, you /// should declare your own constructor with the same signature which chains instead to the <see cref="Container.Container(IRootTargetContainer)"/> /// protected constructor; and then you should apply the configuration yourself in that constructor (falling back to /// <see cref="DefaultConfig"/> if null).</remarks> public Container(IRootTargetContainer targets = null, IContainerConfig config = null) : this(targets) { if (GetType() != typeof(Container)) { throw new InvalidOperationException("This constructor must not be used by derived types because applying configuration will most likely trigger calls to virtual methods on this instance. Please use the protected constructor and apply configuration explicitly in your derived class"); } _scope = new NonTrackingContainerScope(this); (config ?? DefaultConfig).Configure(this, Targets); }
internal NonTrackingContainerScope(ContainerScope parent, bool isRoot) : base(parent, isRoot) { }
/// <summary> /// Resolves an instance of the given <paramref name="serviceType"/> for the given <paramref name="scope"/>. /// </summary> /// <param name="serviceType">The type of service required.</param> /// <param name="scope">The scope to be used for the operation. Will be used for all scoping for the /// created object and any dependencies created for it.</param> /// <returns>An object compatible with the <paramref name="serviceType"/></returns> public object Resolve(Type serviceType, ContainerScope scope) { // resolve, assuming a different scope to this container's scope return(Resolve(new ResolveContext(new ContainerScopeProxy(scope, this), serviceType))); }
private protected virtual void ChildDisposed(ContainerScope child) { }
/// <summary> /// Creates a new Root scope whose container is set to <paramref name="container"/> /// </summary> /// <param name="container"></param> private protected ContainerScope(Container container) { Container = container; _root = this; }
/// <summary> /// Initializes a new instance of the <see cref="ResolveContext"/> class from the given scope. /// /// The <see cref="Container"/> is inherited from the scope's <see cref="ContainerScope.Container"/>. /// </summary> /// <param name="scope">The scope.</param> /// <param name="requestedType">The of object to be resolved from the container.</param> public ResolveContext(ContainerScope scope, Type requestedType) { _scope = scope; RequestedType = requestedType; }
/// <summary> /// Initializes a new instance of the <see cref="ResolveContext"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="requestedType">The type of object to be resolved from the container.</param> public ResolveContext(Container container, Type requestedType) { _scope = container._scope; RequestedType = requestedType; }
public RezolverServiceScope(ContainerScope scope) { _scope = scope; }
/// <summary> /// Creates a new instance of the <see cref="DisposingContainerScope"/> class that /// is optionally treated as a root scope. /// </summary> /// <param name="parent"></param> /// <param name="isRoot"></param> public DisposingContainerScope(ContainerScope parent, bool isRoot) : base(parent, isRoot) { _canActivate = true; }
public ContainerScopeProxy(ContainerScope inner, Container newContainer) : base(newContainer) { _inner = inner; _canActivate = inner._canActivate; }