DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ContextExtensions.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 using System.Collections;
19 using System.Collections.Generic;
20 
21 using Deveel.Data.Services;
22 
23 namespace Deveel.Data {
24  public static class ContextExtensions {
25  public static object ResolveService(this IContext context, Type serviceType, object serviceKey) {
26  return context.Scope.Resolve(serviceType, serviceKey);
27  }
28 
29  public static object ResolveService(this IContext context, Type serviceType) {
30  return context.Scope.Resolve(serviceType);
31  }
32 
33  public static TService ResolveService<TService>(this IContext context, object serviceKey) {
34  return context.Scope.Resolve<TService>(serviceKey);
35  }
36 
37  public static TService ResolveService<TService>(this IContext context) {
38  return context.Scope.Resolve<TService>();
39  }
40 
41  public static IEnumerable ResolveAllServices(this IContext context, Type serviceType) {
42  return context.Scope.ResolveAll(serviceType);
43  }
44 
45  public static IEnumerable<TService> ResolveAllServices<TService>(this IContext context) {
46  return context.Scope.ResolveAll<TService>();
47  }
48 
49  public static void RegisterService(this IContext context, Type serviceType, Type implementationType, object serviceKey) {
50  context.Scope.Register(serviceType, implementationType, serviceKey);
51  }
52 
53  public static void RegisterService(this IContext context, Type serviceType, Type implementationType) {
54  context.Scope.Register(serviceType, implementationType);
55  }
56 
57  public static void RegisterService(this IContext context, Type serviceType, object serviceKey) {
58  context.Scope.Register(serviceType, serviceKey);
59  }
60 
61  public static void RegisterService(this IContext context, Type serviceType) {
62  context.Scope.Register(serviceType);
63  }
64 
65  public static void RegisterService<TService, TImplementation>(this IContext context, object serviceKey)
66  where TImplementation : class, TService {
67  context.Scope.Register<TService, TImplementation>(serviceKey);
68  }
69 
70  public static void RegisterService<TService, TImplementation>(this IContext context)
71  where TImplementation : class, TService {
72  context.Scope.Register<TService, TImplementation>();
73  }
74 
75  public static void RegisterService<TService>(this IContext context, object serviceKey)
76  where TService : class {
77  context.Scope.Register<TService>(serviceKey);
78  }
79 
80  public static void RegisterService<TService>(this IContext context)
81  where TService : class {
82  context.Scope.Register<TService>();
83  }
84 
85  public static void RegisterInstance(this IContext context, Type serviceType, object instance, object serviceKey) {
86  context.Scope.RegisterInstance(serviceType, instance, serviceKey);
87  }
88 
89  public static void RegisterInstance(this IContext context, Type serviceType, object instance) {
90  context.Scope.RegisterInstance(serviceType, instance);
91  }
92 
93  public static void RegisterInstance<TService>(this IContext context, TService instance, object serviceKey)
94  where TService : class {
95  context.Scope.RegisterInstance<TService>(instance, serviceKey);
96  }
97 
98  public static void RegisterInstance<TService>(this IContext context, TService instance)
99  where TService : class {
100  context.Scope.RegisterInstance<TService>(instance);
101  }
102 
103  public static void UnregisterService(this IContext context, Type serviceType) {
104  context.Scope.Unregister(serviceType);
105  }
106 
107  public static void UnregisterService<TService>(this IContext context, object serviceKey) {
108  context.Scope.Unregister<TService>(serviceKey);
109  }
110 
111  public static void UnregisterService<TService>(this IContext context) {
112  context.Scope.Unregister<TService>();
113  }
114  }
115 }
static object ResolveService(this IContext context, Type serviceType)
static IEnumerable ResolveAllServices(this IContext context, Type serviceType)
static object ResolveService(this IContext context, Type serviceType, object serviceKey)
bool Unregister(Type serviceType, object serviceKey)
static void RegisterInstance(this IContext context, Type serviceType, object instance, object serviceKey)
static void RegisterService(this IContext context, Type serviceType, Type implementationType, object serviceKey)
static void UnregisterService(this IContext context, Type serviceType)
static void RegisterService(this IContext context, Type serviceType, Type implementationType)
object Resolve(Type serviceType, object serviceKey)
IEnumerable ResolveAll(Type serviceType)
static void RegisterService(this IContext context, Type serviceType, object serviceKey)
static void RegisterInstance(this IContext context, Type serviceType, object instance)
void Register(ServiceRegistration registration)
static void RegisterService(this IContext context, Type serviceType)