/// <summary>
        /// GetService
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetService <T>()
            where T : class
        {
            Type type = typeof(T);

            if (s_serviceExist.ContainsKey(type) && s_serviceExist[type] != null)
            {
                return((T)s_serviceExist[type]);
            }

            T ret = null;

            if (serviceLocator != null)
            {
                // maybe not defined, it's ok
                try
                {
                    // singleton
                    ret = serviceLocator.GetInstance <T>();
                }
                catch (Exception)
                {
                }
                s_serviceExist[type] = ret;
            }
            if (ret != null)
            {
                return(ret);
            }

//#if DEBUG
//            throw new InvalidOperationException(string.Format("Service {0} is not configured!", typeof(T).Name));
//#endif
            return(null);
        }
示例#2
0
 void ISPServiceBehaviorAccessor.SetContainerAsFarm()
 {
     _container = SharePointServiceLocator.GetCurrentFarm();
     _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig);
     if (_registrar == null)
     {
         throw new NullReferenceException("registrar");
     }
 }
示例#3
0
 void ISPServiceBehaviorAccessor.SetContainer(SPSite site)
 {
     _container = (site != null ? SharePointServiceLocator.GetCurrent(site) : SharePointServiceLocator.GetCurrent());
     _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig);
     if (_registrar == null)
     {
         throw new NullReferenceException("registrar");
     }
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SPServiceRegistrar"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="container">The container.</param>
 public SPServiceRegistrar(SPServiceLocator parent, SPIServiceLocator container)
 {
     _parent    = parent;
     _container = container;
     _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig);
     if (_registrar == null)
     {
         throw new NullReferenceException("registrar");
     }
     LifetimeForRegisters = ServiceRegistrarLifetime.Transient;
 }
示例#5
0
        /// <summary>
        /// Recupera a origemd de ados
        /// </summary>
        /// <param name="actions"></param>
        /// <returns></returns>
        private IPersistenceExecuter GetExecuter(PersistenceAction[] actions)
        {
            var providerName = this.ProviderLocator.GetProviderName(actions.First().EntityFullName);
            IPersistenceExecuter executer = null;

            lock (_objLock)
                if (_executers.TryGetValue(providerName, out executer))
                {
                    return(executer);
                }
            executer = _serviceLocator.GetInstance <IPersistenceExecuter>(string.Format("{0}PersistenceExecuter", providerName));
            if (executer == null)
            {
                throw new Exception(ResourceMessageFormatter.Create(() => Properties.Resources.PersistenceExecuterUndefined).Format());
            }
            lock (_objLock)
            {
                if (!_executers.ContainsKey(providerName))
                {
                    _executers.Add(providerName, executer);
                }
            }
            return(executer);
        }
        /// <summary>
        /// Recupera a origemd de ados
        /// </summary>
        /// <param name="queryInfo"></param>
        /// <returns></returns>
        private IQueryDataSource GetDataSource(QueryInfo queryInfo)
        {
            var providerName            = ProviderLocator.GetProviderName(queryInfo);
            IQueryDataSource dataSource = null;

            lock (_objLock)
                if (_queryDataSources.TryGetValue(providerName, out dataSource))
                {
                    return(dataSource);
                }
            dataSource = _serviceLocator.GetInstance <IQueryDataSource>(string.Format("{0}QueryDataSource", providerName));
            if (dataSource == null)
            {
                throw new Exception(ResourceMessageFormatter.Create(() => Properties.Resources.DataSourceUndefined).Format());
            }
            lock (_objLock)
            {
                if (!_queryDataSources.ContainsKey(providerName))
                {
                    _queryDataSources.Add(providerName, dataSource);
                }
            }
            return(dataSource);
        }
 // resolve
 /// <summary>
 /// Resolves this instance.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <returns></returns>
 public TService Resolve <TService>()
     where TService : class
 {
     try { return(_container.GetInstance <TService>()); }
     catch (Exception ex) { throw new ServiceLocatorResolutionException(typeof(TService), ex); }
 }