Ejemplo n.º 1
0
        internal virtual ItemRegistrationBase BasedOn(ItemRegistrationBase other)
        {
            this.Key    = other.Key;
            this.Module = other.Module;
            this.Scope  = other.Scope;

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Withes the evaluted paramter.
        /// </summary>
        /// <param name="itemRegistration">The builder resolvable item.</param>
        /// <param name="name">The name.</param>
        /// <param name="instanceFactory">The instance factory.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public static ItemRegistrationBase WithEvalutedParamter(
            this ItemRegistrationBase itemRegistration, string name, Func <Type, object> instanceFactory)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(itemRegistration.WithParameter(new EvalutedParamter(name, instanceFactory)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Withes the named parameter.
        /// </summary>
        /// <param name="itemRegistration">The builder resolvable item.</param>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public static ItemRegistrationBase WithNamedParameter(this ItemRegistrationBase itemRegistration,
                                                              string name, object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(itemRegistration.WithParameter(new NamedParameter(name, value)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers type as all interfaces that it implements.
        /// </summary>
        /// <param name="resolvableItemRegistration">The resolvable item builder.</param>
        /// <returns>The resolvable item builder.</returns>
        public static ItemRegistrationBase AsImplementedInterfaces(this ItemRegistrationBase resolvableItemRegistration)
        {
            foreach (var inType in resolvableItemRegistration.InTypes)
            {
                var interfaces = inType.GetInterfaces();
                if (!interfaces.Any())
                {
                    resolvableItemRegistration.AsType = null;
                    return(resolvableItemRegistration);
                }

                resolvableItemRegistration.AsType = interfaces.First();

                foreach (var @interface in interfaces.Skip(1))
                {
                    resolvableItemRegistration.Origin.Register(inType).As(@interface);
                }
            }

            return(resolvableItemRegistration);
        }
Ejemplo n.º 5
0
 public static ItemRegistrationBase Keyed(
     this ItemRegistrationBase resolvableItemRegistrationBase, object key)
 {
     resolvableItemRegistrationBase.Key = key;
     return(resolvableItemRegistrationBase);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Registers type as generic argument.
 /// </summary>
 /// <typeparam name="T">The type, that type should be registered as.</typeparam>
 /// <param name="resolvableItemRegistrationBase">The resolvable item base.</param>
 /// <returns>The resolvable item base.</returns>
 public static ItemRegistrationBase As <T>(this ItemRegistrationBase resolvableItemRegistrationBase)
 {
     resolvableItemRegistrationBase.As(typeof(T));
     return(resolvableItemRegistrationBase);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Registered instance will have only one instance per container including nested liftime scopes.
 /// </summary>
 /// <param name="resolvable">The resolvable builder.</param>
 /// <returns>The resolvable builder.</returns>
 public static ItemRegistrationBase SingleInstance(this ItemRegistrationBase resolvable)
 {
     return(resolvable.WithScope(new SingleInstanceScope()));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Registered instance will live only within liftimescope.
 /// </summary>
 /// <param name="resolvable">The resolvable builder.</param>
 /// <returns>The resolvable builder.</returns>
 public static ItemRegistrationBase PerLifetimeScope(this ItemRegistrationBase resolvable)
 {
     return(resolvable.WithScope(new PerLifetimeScope()));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Default. Every instance request will produce new instance.
 /// </summary>
 /// <param name="resolvable">The resolvable builder.</param>
 /// <returns>The resolvable builder.</returns>
 public static ItemRegistrationBase PerDependency(this ItemRegistrationBase resolvable)
 {
     return(resolvable.WithScope(new PerDependencyScope()));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Withes the scope.
 /// </summary>
 /// <param name="resolvable">The resolvable.</param>
 /// <param name="scope">The scope.</param>
 /// <returns></returns>
 public static ItemRegistrationBase WithScope(this ItemRegistrationBase resolvable, Scope scope)
 {
     resolvable.Scope = scope;
     return(resolvable);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Withes the parameter.
 /// </summary>
 /// <param name="itemRegistration">The builder resolvable item.</param>
 /// <param name="paramter">The paramter.</param>
 /// <returns></returns>
 public static ItemRegistrationBase WithParameter(this ItemRegistrationBase itemRegistration,
                                                  Parameter paramter)
 {
     itemRegistration.Parameters.Add(paramter);
     return(itemRegistration);
 }