Update registration fluent interface to support lists of service overrides (both...
[castle.git] / InversionOfControl / Castle.MicroKernel / Registration / ServiceOverride.cs
blob542e62241ab844c3f047df86c7eb0fb543f9e327
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MicroKernel.Registration
17 using System;
18 using System.Collections.Generic;
20 /// <summary>
21 /// Represents a service override.
22 /// </summary>
23 public class ServiceOverride : Property
25 private readonly Type type;
27 internal ServiceOverride(String key, object value)
28 : base(key, value)
32 internal ServiceOverride(String key, object value, Type type)
33 : base(key, value)
35 this.type = type;
38 /// <summary>
39 /// Gets the optional value type specifier.
40 /// </summary>
41 public Type Type
43 get { return type; }
46 /// <summary>
47 /// Creates a <see cref="ServiceOverrideKey"/> with key.
48 /// </summary>
49 /// <param name="key">The service override key.</param>
50 /// <returns>The new <see cref="ServiceOverrideKey"/></returns>
51 public new static ServiceOverrideKey ForKey(String key)
53 return new ServiceOverrideKey(key);
57 /// <summary>
58 /// Represents a service override key.
59 /// </summary>
60 public class ServiceOverrideKey
62 private readonly String name;
64 internal ServiceOverrideKey(String name)
66 this.name = name;
69 /// <summary>
70 /// Gets the service override key name.
71 /// </summary>
72 public string Name
74 get { return name; }
77 /// <summary>
78 /// Builds the <see cref="ServiceOverride"/> with key/value.
79 /// </summary>
80 /// <param name="value">The service overeride value.</param>
81 /// <returns>The new <see cref="ServiceOverride"/></returns>
82 public ServiceOverride Eq(String value)
84 return new ServiceOverride(name, value);
87 /// <summary>
88 /// Builds the <see cref="ServiceOverride"/> with key/values.
89 /// </summary>
90 /// <param name="value">The service overeride values.</param>
91 /// <returns>The new <see cref="ServiceOverride"/></returns>
92 public ServiceOverride Eq(params String[] value)
94 return new ServiceOverride(name, value);
97 /// <summary>
98 /// Builds the <see cref="ServiceOverride"/> with key/values.
99 /// </summary>
100 /// <param name="value">The service overeride values.</param>
101 /// <returns>The new <see cref="ServiceOverride"/></returns>
102 /// <typeparam name="V">The value type.</typeparam>
103 public ServiceOverride Eq<V>(params String[] value)
105 return new ServiceOverride(name, value, typeof(V));
108 /// <summary>
109 /// Builds the <see cref="ServiceOverride"/> with key/values.
110 /// </summary>
111 /// <param name="value">The service overeride values.</param>
112 /// <returns>The new <see cref="ServiceOverride"/></returns>
113 public ServiceOverride Eq(IEnumerable<String> value)
115 return new ServiceOverride(name, value);
118 /// <summary>
119 /// Builds the <see cref="ServiceOverride"/> with key/values.
120 /// </summary>
121 /// <param name="value">The service overeride values.</param>
122 /// <returns>The new <see cref="ServiceOverride"/></returns>
123 /// <typeparam name="V">The value type.</typeparam>
124 public ServiceOverride Eq<V>(IEnumerable<String> value)
126 return new ServiceOverride(name, value, typeof(V));