Exemple #1
0
        /// <summary>
        /// 该类型是否已注册
        /// </summary>
        /// <param name="type">对象类型</param>
        /// <param name="name">服务名称</param>
        /// <returns></returns>
        public bool IsRegistered(Type type, string name = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(Container.IsRegistered(type));
            }

            return(Container.IsRegisteredWithName(name, type));
        }
 public TInterface Get <TInterface>(string typeName)
 {
     if (container == null)
     {
         throw new Exception("IContainer is null");
     }
     if (container.IsRegisteredWithName <TInterface>(typeName))
     {
         return(container.ResolveNamed <TInterface>(typeName));
     }
     else
     {
         return(default);
Exemple #3
0
 protected override object GetInstance(Type service, string key)
 {
     if (service == null)
     {
         throw new ArgumentNullException(nameof(service));
     }
     if (string.IsNullOrWhiteSpace(key))
     {
         if (_container.IsRegistered(service))
         {
             return(_container.Resolve(service));
         }
     }
     else
     {
         if (_container.IsRegisteredWithName(key, service))
         {
             return(_container.ResolveNamed(key, service));
         }
     }
     throw new Exception($"Could not locate an instances of '{key ?? service.Name}'.");
 }
Exemple #4
0
 public override bool IsRegistered(Type serviceType, string serviceName = null)
 {
     return(string.IsNullOrEmpty(serviceName)
         ? _container.IsRegistered(serviceType)
         : _container.IsRegisteredWithName(serviceName, serviceType));
 }