Example #1
0
        /// <summary>
        /// Registers a type with scoped life style.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="scopeType">Type of the scope.</param>
        /// <exception cref="System.ArgumentNullException">to</exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public static void RegisterScoped(this IContainer self, Type from, Type to, ScopeType scopeType = null)
        {
            //if (from == null)
            //	throw new ArgumentNullException("from");

            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            if (!from.IsAssignableFrom(to))
            {
                const string errorMessageFormat = "Error trying to register the instance: '{0}' is not assignable from '{1}'";
                throw new InvalidOperationException(string.Format(errorMessageFormat, from.FullName, to.FullName));
            }

            self.RegisterScoped(from, () => FastActivator.CreateInstance(to), scopeType);
        }
Example #2
0
 public static IDisposable BeginScope(this IContainer self, ScopeType scopeType = null)
 {
     return(self.BeginScope(scopeType));
 }
Example #3
0
        public static void RegisterScoped(this IContainer self, Type type, Func <object> createInstanceDelegate, ScopeType scopeType = null)
        {
            if (createInstanceDelegate == null)
            {
                throw new ArgumentNullException("createInstanceDelegate");
            }

            self.RegisterScoped(type, createInstanceDelegate as Func <object>, scopeType);
        }
Example #4
0
 /// <summary>
 /// Registers a type with scoped life style.
 /// </summary>
 /// <typeparam name="TFrom">Type that will be requested</typeparam>
 /// <typeparam name="TTo">Type that will actually be returned</typeparam>
 /// <param name="scopeType">Instance name (optional)</param>
 public static void RegisterScoped <TFrom, TTo>(this IContainer self, ScopeType scopeType = null) where TTo : TFrom
 {
     self.RegisterScoped(typeof(TFrom), typeof(TTo), scopeType);
 }