PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/Services.cs

#
C# | 147 lines | 108 code | 20 blank | 19 comment | 18 complexity | f7758d0bcac27b1ee5617f008dac813a MD5 | raw file
  1// ****************************************************************
  2// Copyright 2007, Charlie Poole
  3// This is free software licensed under the NUnit license. You may
  4// obtain a copy of the license at http://nunit.org
  5// ****************************************************************
  6
  7using System;
  8using NUnit.Core;
  9using NUnit.Core.Extensibility;
 10
 11namespace NUnit.Util
 12{
 13	/// <summary>
 14	/// Services is a utility class, which is used to provide access
 15	/// to services in a more simple way than is supported by te
 16	/// ServiceManager class itself.
 17	/// </summary>
 18	public class Services
 19	{
 20		#region AddinManager
 21		private static AddinManager addinManager;
 22		public static AddinManager AddinManager
 23		{
 24			get 
 25			{
 26				if (addinManager == null )
 27					addinManager = (AddinManager)ServiceManager.Services.GetService( typeof( AddinManager ) );
 28
 29				return addinManager; 
 30			}
 31		}
 32		#endregion
 33
 34		#region AddinRegistry
 35		private static IAddinRegistry addinRegistry;
 36		public static IAddinRegistry AddinRegistry
 37		{
 38			get 
 39			{
 40				if (addinRegistry == null)
 41					addinRegistry = (IAddinRegistry)ServiceManager.Services.GetService( typeof( IAddinRegistry ) );
 42                
 43				return addinRegistry;
 44			}
 45		}
 46		#endregion
 47
 48		#region DomainManager
 49		private static DomainManager domainManager;
 50		public static DomainManager DomainManager
 51		{
 52			get
 53			{
 54				if ( domainManager == null )
 55					domainManager = (DomainManager)ServiceManager.Services.GetService( typeof( DomainManager ) );
 56
 57				return domainManager;
 58			}
 59		}
 60		#endregion
 61
 62		#region UserSettings
 63		private static ISettings userSettings;
 64		public static ISettings UserSettings
 65		{
 66			get 
 67			{ 
 68				if ( userSettings == null )
 69					userSettings = (ISettings)ServiceManager.Services.GetService( typeof( ISettings ) );
 70
 71				// Temporary fix needed to run TestDomain tests in test AppDomain
 72				// TODO: Figure out how to set up the test domain correctly
 73				if ( userSettings == null )
 74					userSettings = new SettingsService();
 75
 76				return userSettings; 
 77			}
 78		}
 79		
 80		#endregion
 81
 82		#region RecentFilesService
 83		private static RecentFiles recentFiles;
 84		public static RecentFiles RecentFiles
 85		{
 86			get
 87			{
 88				if ( recentFiles == null )
 89					recentFiles = (RecentFiles)ServiceManager.Services.GetService( typeof( RecentFiles ) );
 90
 91				return recentFiles;
 92			}
 93		}
 94		#endregion
 95
 96		#region TestLoader
 97		private static TestLoader loader;
 98		public static TestLoader TestLoader
 99		{
100			get
101			{
102				if ( loader == null )
103					loader = (TestLoader)ServiceManager.Services.GetService( typeof( TestLoader ) );
104
105				return loader;
106			}
107		}
108		#endregion
109
110		#region TestAgency
111		private static TestAgency agency;
112		public static TestAgency TestAgency
113		{
114			get
115			{
116				if ( agency == null )
117					agency = (TestAgency)ServiceManager.Services.GetService( typeof( TestAgency ) );
118
119				// Temporary fix needed to run ProcessRunner tests in test AppDomain
120				// TODO: Figure out how to set up the test domain correctly
121//				if ( agency == null )
122//				{
123//					agency = new TestAgency();
124//					agency.Start();
125//				}
126
127				return agency;
128			}
129		}
130		#endregion
131
132		#region ProjectLoader
133		private static ProjectService projectService;
134		public static ProjectService ProjectService
135		{
136			get
137			{
138				if ( projectService == null )
139					projectService = (ProjectService)
140						ServiceManager.Services.GetService( typeof( ProjectService ) );
141
142				return projectService;
143			}
144		}
145		#endregion
146	}
147}