ProvideValue() public method

public ProvideValue ( IServiceProvider provider ) : object
provider IServiceProvider
return object
Ejemplo n.º 1
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            object value = null;
            var    type  = (Type)typeExtension.ProvideValue(serviceProvider);

            if (!Instances.TryGetValue(type, out value))
            {
                Instances[type] = value = Activator.CreateInstance(type);
            }
            return(value);
        }
Ejemplo n.º 2
0
		public void ProvideValueWithNameWithProviderResolveSuccess ()
		{
			var x = new TypeExtension ("System.Int32");
			x.ProvideValue (new Resolver (true, true));
		}
Ejemplo n.º 3
0
		public void ProvideValueWithNameWithProviderResolveFail ()
		{
			var x = new TypeExtension ("System.Int32");
			x.ProvideValue (new Resolver (true, false)); // raise an error (do not return null)
		}
Ejemplo n.º 4
0
		public void ProvideValueWithNameWithProviderNoResolver ()
		{
			var x = new TypeExtension ("System.Int32");
			x.ProvideValue (new Resolver (false, false));
		}
Ejemplo n.º 5
0
		public void ProvideValueWithNameWithoutResolver ()
		{
			var x = new TypeExtension ("System.Int32");
			x.ProvideValue (null); // serviceProvider is required.
		}
Ejemplo n.º 6
0
		public void ProvideValueWithType ()
		{
			var x = new TypeExtension (typeof (int));
			Assert.AreEqual (typeof (int), x.ProvideValue (null), "#1"); // serviceProvider is not required.
		}