Ejemplo n.º 1
0
        public void LookUp_DoesNotExist()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            var types = register.LookUp <IAsyncResult>();

            // Assert
            Assert.That(types, Is.Empty);
        }
Ejemplo n.º 2
0
        public void LookUp_Key_Exists()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            Type t = register.LookUp <IMyService>(AvailableServices.Service1);

            // Assert
            Assert.That(t, Is.EqualTo(typeof(MyService1)));
        }
Ejemplo n.º 3
0
        public void LookUp_Key_DoesNotExist()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            Type t = register.LookUp <IMyService>("DOES_NOT_EXIST");

            // Assert
            Assert.That(t, Is.Null);
        }
Ejemplo n.º 4
0
        public void LookUp_Exists()
        {
            // Arrange
            IKeyedServiceRegister register = GetRegistrar();

            // Act
            var types = register.LookUp <IMyService>().ToList();

            // Assert
            Assert.That(types, Has.Count.EqualTo(2));
            Assert.That(types, Contains.Item(typeof(MyService1)));
            Assert.That(types, Contains.Item(typeof(MyService2)));
        }
        /// <summary>
        /// Gets the instance of a service based upon a key.
        /// </summary>
        /// <param name="interfaceType">The interface type</param>
        /// <param name="key">The key.</param>
        /// <returns>The instance of the service, or null if the key is not registered</returns>
        public object GetService(Type interfaceType, object key)
        {
            Type t = _registrar.LookUp(interfaceType, key);

            return(t == null ? null : _services.GetService(t));
        }
 public static IEnumerable <Type> LookUp <TInterface>(this IKeyedServiceRegister register)
 {
     return(register.LookUp(typeof(TInterface)).Distinct());
 }
 public static Type LookUp <TInterface>(this IKeyedServiceRegister register, object key)
 {
     return(register.LookUp(typeof(TInterface), key));
 }