Ejemplo n.º 1
0
        public object GetInstance(IInstanceFactoryRegistration registration)
        {
            var context  = Context;
            var instance = context.Items[_key];

            if (instance == null)
            {
                lock (_lock)
                {
                    instance = context.Items[_key];
                    if (instance == null)
                    {
                        instance            = registration.CreateInstance();
                        context.Items[_key] = instance;

                        if (_disposeOnEnd)
                        {
                            context.RegisterForDispose((IDisposable)instance);                                  // throws exception to make you aware that it doesnt implement IDisposable as expected
                        }
                        // But should throw different Exception than InvalidCastException !?
                        // Could make Initialize method which gets IRegistration where i can be checked?
                    }
                }
            }

            return(instance);
        }
Ejemplo n.º 2
0
		public object GetInstance(IInstanceFactoryRegistration registration)
		{
			if (!_threadLocalInstance.IsValueCreated)
				_threadLocalInstance.Value = registration.CreateInstance();

			return _threadLocalInstance.Value;
		}
Ejemplo n.º 3
0
        public object GetInstance(IInstanceFactoryRegistration registration)
        {
            if (!_threadLocalInstance.IsValueCreated)
            {
                _threadLocalInstance.Value = registration.CreateInstance();
            }

            return(_threadLocalInstance.Value);
        }
Ejemplo n.º 4
0
		public object GetInstance(IInstanceFactoryRegistration registration)
		{
			var session = Context.Session;

			// if run in Application_Start() Session will be null - throw exception, return new instance or try to create temporary storeage (thread storage etc) ?
			if (session == null)
				return registration.CreateInstance();
				//throw new Exception("Type is registered using a SessionLifetime, but the session is not available at this point (maybe you are calling from application startup state)");

			object instance = session[_key];

			if (instance == null)
			{
				instance = registration.CreateInstance();
				session[_key] = instance;
			}

			return instance;
		}
Ejemplo n.º 5
0
        public object GetInstance(IInstanceFactoryRegistration registration)
        {
            // return _instance ?? (_instance = factory(resolver));

            // Need to be thread safe
            if (_instance == null)
            {
                lock (_lock)
                {
                    // If still null when lock is obtained
                    if (_instance == null)
                    {
                        _instance = registration.CreateInstance();
                    }
                }
            }

            return(_instance);
        }
Ejemplo n.º 6
0
		public object GetInstance(IInstanceFactoryRegistration registration)
		{
			// return _instance ?? (_instance = factory(resolver));

			// Need to be thread safe
			if (_instance == null)
			{
				lock (_lock)
				{
					// If still null when lock is obtained
					if (_instance == null)
					{
						_instance = registration.CreateInstance();
					}
				}
			}

			return _instance;
		}
Ejemplo n.º 7
0
        public object GetInstance(IInstanceFactoryRegistration registration)
        {
            var instance = _cache.Get(_key);

            if (instance == null)
            {
                lock (_lock)
                {
                    instance = _cache.Get(_key);
                    if (instance == null)
                    {
                        instance = registration.CreateInstance();
                        _cache.Add(_key, instance, _cachePolicy);
                    }
                }
            }

            return(instance);
        }
Ejemplo n.º 8
0
		public object GetInstance(IInstanceFactoryRegistration registration)
		{
			var instance = _cache.Get(_key);

			if (instance == null)
			{
				lock (_lock)
				{
					instance = _cache.Get(_key);
					if (instance == null)
					{
						instance = registration.CreateInstance();
						_cache.Add(_key, instance, _cachePolicy);
					}
				}
			}

			return instance;
		}
Ejemplo n.º 9
0
        public object GetInstance(IInstanceFactoryRegistration registration)
        {
            var session = Context.Session;

            // if run in Application_Start() Session will be null - throw exception, return new instance or try to create temporary storeage (thread storage etc) ?
            if (session == null)
            {
                return(registration.CreateInstance());
            }
            //throw new Exception("Type is registered using a SessionLifetime, but the session is not available at this point (maybe you are calling from application startup state)");

            object instance = session[_key];

            if (instance == null)
            {
                instance      = registration.CreateInstance();
                session[_key] = instance;
            }

            return(instance);
        }
Ejemplo n.º 10
0
 public object GetInstance(IInstanceFactoryRegistration registration)
 {
     return(registration.CreateInstance());
 }
Ejemplo n.º 11
0
		public object GetInstance(IInstanceFactoryRegistration registration)
		{
			return registration.CreateInstance();
		}