Exemple #1
0
        private object TryGetInstance(string instanceKey, Func <object> createInstance)
        {
            try
            {
                object instance = createInstance();

                if (!session.Contains(instanceKey))
                {
                    SetInstance(instanceKey, createInstance);
                }

                var sessionInstance = session.Get <object>(instanceKey);

                if (sessionInstance != null)
                {
                    instance = sessionInstance;
                }

                return(instance);
            }
            catch (Exception ex)
            {
                Tracing.Start("Extensibility - Light Inject - PerSessionLifeTime - Start of Error");
                Tracing.Error(ex.Message);
                Tracing.Error(ex.StackTrace);
                Tracing.Stop("Extensibility - Light Inject - PerSessionLifeTime - End of Error");
                return(createInstance());
            }
        }