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

Last change on this file since 948 was 948, checked in by svonolfe, 12 years ago

Refactored DAL (#372)

File size: 4.2 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;
25using HeuristicLab.Hive.Contracts.Interfaces;
26
27/// <summary>
28/// The service locator for the server core
29/// </summary>
30public class ServiceLocator {
31  private static DiscoveryService discoveryService =
32    new DiscoveryService();
33
34  private static ITransactionManager transManager = null;
35
36  private static IClientAdapter clientAdapter = null;
37
38  private static IClientGroupAdapter clientGroupAdapter = null;
39
40  private static IResourceAdapter resourceAdapter = null;
41
42  private static IUserAdapter userAdapter = null;
43
44  private static IUserGroupAdapter userGroupAdapter = null;
45
46  private static IPermissionOwnerAdapter permOwnerAdapter = null;
47
48  /// <summary>
49  /// Gets the db transaction manager
50  /// </summary>
51  /// <returns></returns>
52  [MethodImpl(MethodImplOptions.Synchronized)]
53  public static ITransactionManager GetTransactionManager() {
54    if (transManager == null) {
55      transManager = discoveryService.GetInstances<ITransactionManager>()[0];
56    }
57
58    return transManager;
59  }
60
61  /// <summary>
62  /// Gets the client database adapter
63  /// </summary>
64  /// <returns></returns>
65  [MethodImpl(MethodImplOptions.Synchronized)]
66  public static IClientAdapter GetClientAdapter() {
67    if (clientAdapter == null) {
68      clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
69    }
70
71    return clientAdapter;
72  }
73
74  /// <summary>
75  /// Gets the client group database adapter
76  /// </summary>
77  /// <returns></returns>
78  [MethodImpl(MethodImplOptions.Synchronized)]
79  public static IClientGroupAdapter GetClientGroupAdapter() {
80    if (clientGroupAdapter == null) {
81      clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
82    }
83
84    return clientGroupAdapter;
85  }
86
87  /// <summary>
88  /// Gets the resource database adapter
89  /// </summary>
90  /// <returns></returns>
91  [MethodImpl(MethodImplOptions.Synchronized)]
92  public static IResourceAdapter GetResourceAdapter() {
93    if (resourceAdapter == null) {
94      resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
95    }
96
97    return resourceAdapter;
98  }
99
100  /// <summary>
101  /// Gets the user database adapter
102  /// </summary>
103  /// <returns></returns>
104  [MethodImpl(MethodImplOptions.Synchronized)]
105  public static IUserAdapter GetUserAdapter() {
106    if (userAdapter == null) {
107      userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
108    }
109
110    return userAdapter;
111  }
112
113  /// <summary>
114  /// Gets the user group database adapter
115  /// </summary>
116  /// <returns></returns>
117  [MethodImpl(MethodImplOptions.Synchronized)]
118  public static IUserGroupAdapter GetUserGroupAdapter() {
119    if (userGroupAdapter == null) {
120      userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
121    }
122
123    return userGroupAdapter;
124  }
125
126  /// <summary>
127  /// Gets the permission owner database adapter
128  /// </summary>
129  /// <returns></returns>
130  [MethodImpl(MethodImplOptions.Synchronized)]
131  public static IPermissionOwnerAdapter GetPermissionOwnerAdapter() {
132    if (permOwnerAdapter == null) {
133      permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
134    }
135
136    return permOwnerAdapter;
137  }
138}
Note: See TracBrowser for help on using the repository browser.