Ejemplo n.º 1
0
        /// <summary>
        /// Marks the dependency as a different instance for . The instances will not be shared between scopes. (default)
        /// </summary>
        /// <param name="builder">The registration to modify.</param>
        /// <returns>The IRegistrationBuilder, for chaining purpose.</returns>
        public static IRegistrationBuilder InstancePerDependency(this IRegistrationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddOptions(data =>
            {
                data["InstanceScope"] = new InstanceScopeConfig {
                    Scope = InstanceScope.PerDependency
                };
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Marks the dependency as a single instance for each scope with the given name. The instances will not be shared between scopes, and a scope without the right name or without a parent with the right name will not contain the dependency..
        /// </summary>
        /// <param name="builder">The registration to modify.</param>
        /// <param name="name">The name of the scope.</param>
        /// <returns>The IRegistrationBuilder, for chaining purpose.</returns>
        public static IRegistrationBuilder InstancePerNamedLifetimeScope(this IRegistrationBuilder builder, string name)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddOptions(data =>
            {
                data["InstanceScope"] = new InstanceScopeConfig {
                    Scope = InstanceScope.PerNamedLifeTimeScope, Name = name
                };
            }));
        }