Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/ServiceLocator.cs @ 929

Last change on this file since 929 was 925, checked in by svonolfe, 16 years ago

Added caching, thread safety to DataAccess layer (#372)

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
23using HeuristicLab.PluginInfrastructure;
24using System.Runtime.CompilerServices;
25
26/// <summary>
27/// The service locator for the server core
28/// </summary>
29public class ServiceLocator {
30  private static DiscoveryService discoveryService =
31    new DiscoveryService();
32
33  private static ITransactionManager transManager = null;
34
35  private static IClientAdapter clientAdapter = null;
36
37  private static IClientGroupAdapter clientGroupAdapter = null;
38
39  private static IResourceAdapter resourceAdapter = null;
40
41  private static IUserAdapter userAdapter = null;
42
43  private static IUserGroupAdapter userGroupAdapter = null;
44
45  private static IPermissionOwnerAdapter permOwnerAdapter = null;
46
47  /// <summary>
48  /// Gets the db transaction manager
49  /// </summary>
50  /// <returns></returns>
51  [MethodImpl(MethodImplOptions.Synchronized)]
52  public static ITransactionManager GetTransactionManager() {
53    if (transManager == null) {
54      transManager = discoveryService.GetInstances<ITransactionManager>()[0];
55    }
56
57    return transManager;
58  }
59
60  /// <summary>
61  /// Gets the client database adapter
62  /// </summary>
63  /// <returns></returns>
64  [MethodImpl(MethodImplOptions.Synchronized)]
65  public static IClientAdapter GetClientAdapter() {
66    if (clientAdapter == null) {
67      clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
68    }
69
70    return clientAdapter;
71  }
72
73  /// <summary>
74  /// Gets the client group database adapter
75  /// </summary>
76  /// <returns></returns>
77  [MethodImpl(MethodImplOptions.Synchronized)]
78  public static IClientGroupAdapter GetClientGroupAdapter() {
79    if (clientGroupAdapter == null) {
80      clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
81    }
82
83    return clientGroupAdapter;
84  }
85
86  /// <summary>
87  /// Gets the resource database adapter
88  /// </summary>
89  /// <returns></returns>
90  [MethodImpl(MethodImplOptions.Synchronized)]
91  public static IResourceAdapter GetResourceAdapter() {
92    if (resourceAdapter == null) {
93      resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
94    }
95
96    return resourceAdapter;
97  }
98
99  /// <summary>
100  /// Gets the user database adapter
101  /// </summary>
102  /// <returns></returns>
103  [MethodImpl(MethodImplOptions.Synchronized)]
104  public static IUserAdapter GetUserAdapter() {
105    if (userAdapter == null) {
106      userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
107    }
108
109    return userAdapter;
110  }
111
112  /// <summary>
113  /// Gets the user group database adapter
114  /// </summary>
115  /// <returns></returns>
116  [MethodImpl(MethodImplOptions.Synchronized)]
117  public static IUserGroupAdapter GetUserGroupAdapter() {
118    if (userGroupAdapter == null) {
119      userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
120    }
121
122    return userGroupAdapter;
123  }
124
125  /// <summary>
126  /// Gets the permission owner database adapter
127  /// </summary>
128  /// <returns></returns>
129  [MethodImpl(MethodImplOptions.Synchronized)]
130  public static IPermissionOwnerAdapter GetPermissionOwnerAdapter() {
131    if (permOwnerAdapter == null) {
132      permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
133    }
134
135    return permOwnerAdapter;
136  }
137}
Note: See TracBrowser for help on using the repository browser.