/// <summary>
        ///     Enregistre l'instance d'une interface
        /// </summary>
        /// <typeparam name="TInterface">Interface</typeparam>
        /// <typeparam name="TInstance">Instance de l'interface</typeparam>
        public void RegisterInstance <TInterface, TInstance>()
            where TInstance : class, TInterface, new()
        {
            var instance = new TInstance();

            RegisterInstance <TInterface>(instance);
        }
示例#2
0
 private static Func <object> DefaultFactory <TInstance>() where TInstance : class, new()
 {
     return(() =>
     {
         var instance = new TInstance();
         InjectInto(instance);
         return instance;
     });
 }
        public object AcquireObject <TInstance>() where TInstance : class, new()
        {
            var type = typeof(TInstance);

            if (CachedObjects.ContainsKey(type))
            {
                return(CachedObjects[type]);
            }
            lock (_lock)
            {
                var instance = new TInstance();
                CachedObjects.Add(type, instance);
                return(CachedObjects[type]);
            }
        }
        public TInstance AcquireObject <TInstance>() where TInstance : class, new()
        {
            var type = typeof(TInstance);

            //如果已有该对象,返回
            if (CachedObjects.ContainsKey(type))
            {
                return(CachedObjects[type] as TInstance);
            }

            lock (_lock) {
                TInstance instance = new TInstance();
                CachedObjects.Add(type, instance);
                return(CachedObjects[type] as TInstance);
            }
        }
示例#5
0
        /// <summary>
        /// Liefert eine Instanz vom Typ TInstance zurück.
        /// Falls noch keine Instanz erstellt wurde, wird automatisch eine neue erzeugt.
        /// </summary>
        public static TInstance GetInstance <TInstance>()
            where TInstance : class, new()
        {
            Type   type = typeof(TInstance);
            string key  = type.FullName;

            TInstance result;

            lock (m_instancesLock)
            {
                if (m_instances.ContainsKey(key))
                {
                    result = m_instances[key] as TInstance;
                }
                else
                {
                    result = new TInstance();
                    m_instances.Add(key, result);
                }
            }

            return(result);
        }
        public TInstance AcquireObject <TInstance>() where TInstance : class, new()
        {
            TInstance instance = new TInstance();

            return(instance);
        }
示例#7
0
        public object AcquireObject <TInstance>() where TInstance : class, new()
        {
            var instance = new TInstance();

            return(instance);
        }