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 |
|
---|
22 | using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
|
---|
23 | using HeuristicLab.PluginInfrastructure;
|
---|
24 | using System.Runtime.CompilerServices;
|
---|
25 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
26 |
|
---|
27 | /// <summary>
|
---|
28 | /// The service locator for the server core
|
---|
29 | /// </summary>
|
---|
30 | public 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 | private static IJobAdapter jobAdapter = null;
|
---|
49 |
|
---|
50 | private static IJobResultsAdapter jobResultsAdapter = null;
|
---|
51 |
|
---|
52 | /// <summary>
|
---|
53 | /// Gets the db transaction manager
|
---|
54 | /// </summary>
|
---|
55 | /// <returns></returns>
|
---|
56 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
57 | public static ITransactionManager GetTransactionManager() {
|
---|
58 | if (transManager == null) {
|
---|
59 | transManager = discoveryService.GetInstances<ITransactionManager>()[0];
|
---|
60 | }
|
---|
61 |
|
---|
62 | return transManager;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /// <summary>
|
---|
66 | /// Gets the client database adapter
|
---|
67 | /// </summary>
|
---|
68 | /// <returns></returns>
|
---|
69 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
70 | public static IClientAdapter GetClientAdapter() {
|
---|
71 | if (clientAdapter == null) {
|
---|
72 | clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0];
|
---|
73 | }
|
---|
74 |
|
---|
75 | return clientAdapter;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /// <summary>
|
---|
79 | /// Gets the client group database adapter
|
---|
80 | /// </summary>
|
---|
81 | /// <returns></returns>
|
---|
82 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
83 | public static IClientGroupAdapter GetClientGroupAdapter() {
|
---|
84 | if (clientGroupAdapter == null) {
|
---|
85 | clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0];
|
---|
86 | }
|
---|
87 |
|
---|
88 | return clientGroupAdapter;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /// <summary>
|
---|
92 | /// Gets the resource database adapter
|
---|
93 | /// </summary>
|
---|
94 | /// <returns></returns>
|
---|
95 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
96 | public static IResourceAdapter GetResourceAdapter() {
|
---|
97 | if (resourceAdapter == null) {
|
---|
98 | resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0];
|
---|
99 | }
|
---|
100 |
|
---|
101 | return resourceAdapter;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /// <summary>
|
---|
105 | /// Gets the user database adapter
|
---|
106 | /// </summary>
|
---|
107 | /// <returns></returns>
|
---|
108 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
109 | public static IUserAdapter GetUserAdapter() {
|
---|
110 | if (userAdapter == null) {
|
---|
111 | userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
|
---|
112 | }
|
---|
113 |
|
---|
114 | return userAdapter;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /// <summary>
|
---|
118 | /// Gets the user group database adapter
|
---|
119 | /// </summary>
|
---|
120 | /// <returns></returns>
|
---|
121 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
122 | public static IUserGroupAdapter GetUserGroupAdapter() {
|
---|
123 | if (userGroupAdapter == null) {
|
---|
124 | userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
|
---|
125 | }
|
---|
126 |
|
---|
127 | return userGroupAdapter;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /// <summary>
|
---|
131 | /// Gets the permission owner database adapter
|
---|
132 | /// </summary>
|
---|
133 | /// <returns></returns>
|
---|
134 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
135 | public static IPermissionOwnerAdapter GetPermissionOwnerAdapter() {
|
---|
136 | if (permOwnerAdapter == null) {
|
---|
137 | permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
|
---|
138 | }
|
---|
139 |
|
---|
140 | return permOwnerAdapter;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /// <summary>
|
---|
144 | /// Gets the job database adapter
|
---|
145 | /// </summary>
|
---|
146 | /// <returns></returns>
|
---|
147 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
148 | public static IJobAdapter GetJobAdapter() {
|
---|
149 | if (jobAdapter == null) {
|
---|
150 | jobAdapter = discoveryService.GetInstances<IJobAdapter>()[0];
|
---|
151 | }
|
---|
152 |
|
---|
153 | return jobAdapter;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /// <summary>
|
---|
157 | /// Gets the job results database adapter
|
---|
158 | /// </summary>
|
---|
159 | /// <returns></returns>
|
---|
160 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
161 | public static IJobResultsAdapter GetJobResultsAdapter() {
|
---|
162 | if (jobResultsAdapter == null) {
|
---|
163 | jobResultsAdapter = discoveryService.GetInstances<IJobResultsAdapter>()[0];
|
---|
164 | }
|
---|
165 |
|
---|
166 | return jobResultsAdapter;
|
---|
167 | }
|
---|
168 | } |
---|