Dispose() public méthode

public Dispose ( ) : void
Résultat void
Exemple #1
0
 private static void CleanupFields()
 {
     if (container != null)
     {
         container.Dispose();
         container = null;
     }
     if (serviceProvider != null)
     {
         serviceProvider.Dispose();
         serviceProvider = null;
     }
     if (composition != null)
     {
         composition.Dispose();
         composition = null;
     }
     if (globalCatalog != null)
     {
         globalCatalog.Dispose();
         globalCatalog = null;
     }
     componentHost       = null;
     catalogProvider     = null;
     localComponentModel = null;
 }
		[Test] // RemoveService (Type, Boolean)
		public void RemoveService2_Disposed ()
		{
			ServiceContainer sc;
			ServiceContainer parent;

			ArrayList serviceInstance1 = new ArrayList ();
			ArrayList serviceInstance2 = new ArrayList ();

			Type serviceType1 = typeof (IList);
			Type serviceType2 = typeof (IEnumerable);

			parent = new ServiceContainer ();
			sc = new ServiceContainer (parent);
			sc.AddService (serviceType1, serviceInstance1, true);
			sc.AddService (serviceType2, serviceInstance2, false);

			sc.Dispose ();

			sc.RemoveService (serviceType1, false);
			sc.RemoveService (serviceType2, false);

			Assert.AreSame (serviceInstance1, sc.GetService (serviceType1), "#A1");
			Assert.IsNull (sc.GetService (serviceType2), "#A2");

			sc.RemoveService (serviceType1, true);
			sc.RemoveService (serviceType2, true);

			Assert.IsNull (sc.GetService (serviceType1), "#B1");
			Assert.IsNull (sc.GetService (serviceType2), "#B2");
		}
		[Test] // RemoveService (Type)
		public void RemoveService1_Disposed ()
		{
			ServiceContainer sc;
			ServiceContainer parent;
			
			ArrayList serviceInstance1 = new ArrayList ();

			Type serviceType1 = typeof (IList);

			parent = null;
			sc = new ServiceContainer (parent);
			sc.AddService (serviceType1, serviceInstance1);
			sc.Dispose ();

			sc.RemoveService (typeof (DateTime));
		}
		[Test] // AddService (Type, ServiceCreatorCallback)
		public void AddService2_Disposed ()
		{
			object service;
			ServiceContainer sc;

			object callback = new ServiceCreatorCallback (
				Svc.ServiceCreator);

			sc = new ServiceContainer ();
			sc.AddService (typeof (Svc), callback);
			service = sc.GetService (typeof (Svc));
			Assert.IsNotNull (service, "#A");

			sc.Dispose ();

			service = sc.GetService (typeof (Svc));
			Assert.IsNull (service, "#B");

			sc.AddService (typeof (Svc), callback);
			service = sc.GetService (typeof (Svc));
			Assert.IsNotNull (service, "#C");
		}
		public void AddService1_Disposed ()
		{
			object service;
			ServiceContainer sc;

			object serviceInstance1 = new ArrayList ();
			object serviceInstance2 = new Hashtable ();

			sc = new ServiceContainer ();
			sc.AddService (typeof (ICollection), serviceInstance1);
			service = sc.GetService (typeof (ICollection));
			Assert.IsNotNull (service, "#A1");
			Assert.AreSame (serviceInstance1, service, "#A2");

			sc.Dispose ();

			service = sc.GetService (typeof (ICollection));
			Assert.IsNull (service, "#B");

			sc.AddService (typeof (ICollection), serviceInstance2);
			service = sc.GetService (typeof (ICollection));
			Assert.IsNotNull (service, "#C1");
			Assert.AreSame (serviceInstance2, service, "#C2");
		}