Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IxSingletonProvider"/> class.
        /// </summary>
        /// <param name="host">IndirectX host.</param>
        public IxSingletonProvider(
            IxHost host,
            IxProviderNode parentNode,
            IxStdProviderConfig config,
            IxInstanceFactory instanceFactory,
            IxVisibilityFilter exportFilter,
            IxVisibilityFilter exportToParentFilter,
            IxVisibilityFilter importFilter,
            IxScopeBinderDelegate scopeBinder)
            : base(
                host,
                parentNode,
                config,
                instanceFactory,
                exportFilter,
                exportToParentFilter,
                importFilter,
                scopeBinder,
                config.AutoDisposeEnabled,
                config.DisposeHandler)
        {
            if (parentNode == null)
            {
                throw new ArgumentNullException(nameof(parentNode));
            }

            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            // Adding self provided as default for children.
            VisibleNodes.Add(new IxIdentifier(Identifier.Type), new IxResolvePath(this, new IxProviderNode[] { }));
        }
Пример #2
0
        /// <summary>
        /// Adds standard provider node.
        /// </summary>
        /// <typeparam name="TContract">Registration target type.</typeparam>
        /// <param name="nodesBuilder">Nodes builder.</param>
        /// <param name="name">Registration <c>name</c>.</param>
        /// <param name="scopeBinding">Scope binding strategy config (registration, transient, etc.).</param>
        /// <param name="importFilter">Import filter. Controls which registrations of parent node are visible for current node.</param>
        /// <param name="exportToParentFilter">
        /// Export to parent filter. Controls which registrations of <c>this</c> node will be
        /// visible in parent node.
        /// </param>
        /// <param name="exportFilter">Export to children filter. Controls which registrations of <c>this</c> node.</param>
        /// <param name="instanceBuilder">Instance builder config. (Class constructor, existing instance, etc.).</param>
        /// <param name="multiplicity">Multiplicity config. (Singleton, pool, <c>factory</c> etc.).</param>
        /// <param name="disposeHandler">Overrides dispose operation.</param>
        /// <param name="nodes">Action that build nested <c>nodes</c>.</param>
        /// <returns>Fluent syntax continuation.</returns>
        public static IIxBuilder <ICollection <IIxProviderNodeConfig> > Add <TContract>(
            this IIxBuilder <ICollection <IIxProviderNodeConfig> > nodesBuilder,
            string name = null,
            IIxScopeBindingConfig scopeBinding             = null,
            IIxVisibilityFilterConfig importFilter         = null,
            IIxVisibilityFilterConfig exportToParentFilter = null,
            IIxVisibilityFilterConfig exportFilter         = null,
            IIxInstanceBuilderConfig instanceBuilder       = null,
            IIxMultiplicityConfig multiplicity             = null,
            bool autoDisposeEnabled = false,
            IxDisposeHandlerDelegate disposeHandler = null,
            Action <IIxBuilder <ICollection <IIxProviderNodeConfig> > > nodes = null)
        {
            var depNode = new IxStdProviderConfig
            {
                InstanceBuilder      = instanceBuilder,
                Identifier           = new IxIdentifier(typeof(TContract), name),
                ScopeBinding         = scopeBinding,
                Multiplicity         = multiplicity,
                ImportFilter         = importFilter,
                ExportFilter         = exportFilter,
                ExportToParentFilter = exportToParentFilter,
                AutoDisposeEnabled   = autoDisposeEnabled,
                DisposeHandler       = disposeHandler
            };

            nodesBuilder.Config.Add(depNode);

            nodes?.Invoke(
                new IxBuilder <ICollection <IIxProviderNodeConfig> >
            {
                Config = depNode.Nodes
            });

            return(nodesBuilder);
        }