Ejemplo n.º 1
0
        /// <summary>
        /// Registers new type.
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="implementationType"></param>
        /// <param name="lifetime"></param>
        public static void Register(Type interfaceType, Type implementationType,
                                    NegumObjectLifetime lifetime = NegumObjectLifetime.Transient)
        {
            if (!interfaceType.IsInterface || !implementationType.IsClass)
            {
                return;
            }

            Registerer(lifetime, interfaceType, implementationType);
        }
Ejemplo n.º 2
0
        public static void Register(NegumObjectLifetime lifetime, Type interfaceType, Type implementationType)
        {
            if (lifetime == NegumObjectLifetime.Singleton)
            {
                if (Instances.ContainsKey(interfaceType))
                {
                    Instances.Remove(interfaceType);
                }

                Instances.Add(interfaceType, Activator.CreateInstance(implementationType));
            }
            else
            {
                if (Types.ContainsKey(interfaceType))
                {
                    Types.Remove(interfaceType);
                }

                Types.Add(interfaceType, implementationType);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Registers new type.
 /// </summary>
 /// <typeparam name="TInterface">Interface type.</typeparam>
 /// <typeparam name="TClass">Implementation type.</typeparam>
 public static void Register <TInterface, TClass>(NegumObjectLifetime lifetime = NegumObjectLifetime.Transient)
     where TClass : class, TInterface =>
 Register(typeof(TInterface), typeof(TClass), lifetime);