Example #1
0
 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}.");
 }
Example #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);
        }
Example #3
0
 public TComponent Resolve <TComponent>(string key)
 {
     return(container.ResolveKeyed <TComponent>(key));
 }