コード例 #1
0
ファイル: Bootstrap.cs プロジェクト: HReader/HReader.Desktop
 protected override object GetInstance(Type serviceType, string key)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         if (container.IsRegistered(serviceType))
         {
             return(container.Resolve(serviceType));
         }
     }
     else if (container.IsRegisteredWithKey(key, serviceType))
     {
         return(container.ResolveKeyed(key, serviceType));
     }
     throw new Exception($"Could not locate any instances of contract {key ?? serviceType.Name}.");
 }
コード例 #2
0
        protected override object GetInstance(Type service, string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                if (_container.IsRegistered(service))
                {
                    return(_container.Resolve(service));
                }
            }
            else
            {
                if (_container.IsRegisteredWithKey(key, service))
                {
                    return(_container.ResolveKeyed(key, service));
                }
            }

            var msgFormat = "Could not locate any instances of contract {0}.";
            var msg       = string.Format(msgFormat, key ?? service.Name);

            throw new Exception(msg);
        }