DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ServiceRegistration.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
19 namespace Deveel.Data.Services {
20  public sealed class ServiceRegistration {
21  private object instance;
22 
23  public ServiceRegistration(Type serviceType, Type implementationType) {
24  if (serviceType == null)
25  throw new ArgumentNullException("serviceType");
26  if (implementationType == null)
27  throw new ArgumentNullException("implementationType");
28 
29  if (!serviceType.IsAssignableFrom(implementationType))
30  throw new ArgumentException(
31  String.Format("The implementation type '{0} is not assignable from the service type '{1}'.",
32  implementationType, serviceType));
33 
34  ServiceType = serviceType;
35  ImplementationType = implementationType;
36  }
37 
38  public Type ServiceType { get; private set; }
39 
40  public Type ImplementationType { get; private set; }
41 
42  public object ServiceKey { get; set; }
43 
44  public string Scope { get; set; }
45 
46  public object Instance {
47  get { return instance; }
48  set {
49  if (value != null &&
50  !ServiceType.IsInstanceOfType(value))
51  throw new ArgumentException(String.Format("The instance is not assignable from '{0}'.", ServiceType));
52 
53  instance = value;
54  }
55  }
56  }
57 }
ServiceRegistration(Type serviceType, Type implementationType)