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); }
public object GetInstance(IInstanceFactoryRegistration registration) { if (!_threadLocalInstance.IsValueCreated) _threadLocalInstance.Value = registration.CreateInstance(); return _threadLocalInstance.Value; }
public object GetInstance(IInstanceFactoryRegistration registration) { if (!_threadLocalInstance.IsValueCreated) { _threadLocalInstance.Value = registration.CreateInstance(); } return(_threadLocalInstance.Value); }
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; }
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); }
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; }
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); }
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; }
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); }
public object GetInstance(IInstanceFactoryRegistration registration) { return(registration.CreateInstance()); }
public object GetInstance(IInstanceFactoryRegistration registration) { return registration.CreateInstance(); }