Пример #1
0
            /// <summary>
            /// Gets the service.
            /// </summary>
            /// <param name="parameter">The parameter.</param>
            /// <returns>TService.</returns>
            /// <exception cref="System.ArgumentException">No such value supported in enum  + typeof(CacheType).ToString()</exception>
            public TService GetService(object parameter = null)
            {
                switch (CacheType)
                {
                case CacheType.Instance:
                    return(ServiceInstance);

                case CacheType.Factory:
                    return(ServiceFactory(parameter));

                case CacheType.LazyInstance:
                    var rval = ServiceInstance;
                    if (rval == null || rval.Equals(default(TService)))
                    {
                        lock (this)
                        {
                            if (ServiceInstance == null || ServiceInstance.Equals(default(TService)))
                            {
                                return(ServiceInstance = ServiceFactory(parameter));
                            }
                        }
                    }
                    return(rval);

                case CacheType.AsyncFactory:                //  not really suguessed to acces async factory in sync method cos may lead to deadlock ,
                case CacheType.AsyncLazyInstance:           // but still can do.
                    Task <TService> t = GetServiceAsync(parameter);
                    return(t.Result);

                default:
                    throw new ArgumentException("No such value supported in enum " + typeof(CacheType).ToString());
                }
            }
Пример #2
0
 /// <summary>
 /// Gets the is value created.
 /// </summary>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 public bool GetIsValueCreated()
 {
     return(ServiceInstance != null && (!ServiceInstance.Equals(default(TService))));
 }