Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 253 lines (230 sloc) 7.435 kB
6e1e0a1 Updated licensing terms to reflect dual-license with Ms-PL
Nate Kohari authored
1 #region License
2 //
fe03508 Merged from fork
Nate Kohari authored
3 // Author: Nate Kohari <nate@enkari.com>
5b24b7a Updated copyright, fixed line endings
unknown authored
4 // Copyright (c) 2007-2010, Enkari, Ltd.
fe03508 Merged from fork
Nate Kohari authored
5 //
6e1e0a1 Updated licensing terms to reflect dual-license with Ms-PL
Nate Kohari authored
6 // Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
7 // See the file LICENSE.txt for details.
fe03508 Merged from fork
Nate Kohari authored
8 //
9 #endregion
10 #region Using Directives
11 using System;
12 using System.Collections.Generic;
13 using Ninject.Activation;
14 using Ninject.Infrastructure;
15 using Ninject.Parameters;
16 #endregion
17
18 namespace Ninject.Planning.Bindings
19 {
d3ca0c5 Removed ISelector from ReadonlyKernel
Patrick Ineichen authored
20 using Ninject.Selection;
21
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
22 /// <summary>
23 /// Contains information about a service registration.
24 /// </summary>
25 public class Binding : IBinding
26 {
27 /// <summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
28 /// Initializes a new instance of the <see cref="Binding"/> class.
29 /// </summary>
30 /// <param name="service">The service that is controlled by the binding.</param>
31 public Binding(Type service)
32 {
33 this.Service = service;
b60dcc2 @remogloor Simplify Default Scope implementation
remogloor authored
34 this.BindingConfiguration = new BindingConfiguration();
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
35 }
36
37 /// <summary>
38 /// Initializes a new instance of the <see cref="Binding"/> class.
39 /// </summary>
40 /// <param name="service">The service that is controlled by the binding.</param>
41 /// <param name="configuration">The binding configuration.</param>
42 public Binding(Type service, IBindingConfiguration configuration)
43 {
44 this.Service = service;
45 this.BindingConfiguration = configuration;
46 }
47
48 /// <summary>
49 /// Gets or sets the binding configuration.
50 /// </summary>
51 /// <value>The binding configuration.</value>
52 public IBindingConfiguration BindingConfiguration { get; private set; }
53
54 /// <summary>
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
55 /// Gets the service type that is controlled by the binding.
56 /// </summary>
57 public Type Service { get; private set; }
58
59 /// <summary>
60 /// Gets the binding's metadata.
61 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
62 /// <value></value>
63 public IBindingMetadata Metadata
64 {
65 get
66 {
67 return this.BindingConfiguration.Metadata;
68 }
69 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
70
71 /// <summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
72 /// Gets or sets the type of target for the binding.
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
73 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
74 /// <value></value>
75 public BindingTarget Target
76 {
77 get
78 {
79 return this.BindingConfiguration.Target;
80 }
81
82 set
83 {
84 this.BindingConfiguration.Target = value;
85 }
86 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
87
88 /// <summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
89 /// Gets or sets a value indicating whether the binding was implicitly registered.
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
90 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
91 /// <value></value>
92 public bool IsImplicit
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
93 {
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
94 get
95 {
96 return this.BindingConfiguration.IsImplicit;
97 }
98
99 set
100 {
101 this.BindingConfiguration.IsImplicit = value;
102 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
103 }
104
105 /// <summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
106 /// Gets a value indicating whether the binding has a condition associated with it.
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
107 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
108 /// <value></value>
109 public bool IsConditional
110 {
111 get
112 {
113 return this.BindingConfiguration.IsConditional;
114 }
115 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
116
117 /// <summary>
118 /// Gets or sets the condition defined for the binding.
119 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
120 /// <value></value>
121 public Func<IRequest, bool> Condition
122 {
123 get
124 {
125 return this.BindingConfiguration.Condition;
126 }
127 set
128 {
129 this.BindingConfiguration.Condition = value;
130 }
131 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
132
133 /// <summary>
134 /// Gets or sets the callback that returns the provider that should be used by the binding.
135 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
136 /// <value></value>
137 public Func<IContext, IProvider> ProviderCallback
138 {
139 get
140 {
141 return this.BindingConfiguration.ProviderCallback;
142 }
143
144 set
145 {
146 this.BindingConfiguration.ProviderCallback = value;
147 }
148 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
149
150 /// <summary>
151 /// Gets or sets the callback that returns the object that will act as the binding's scope.
152 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
153 /// <value></value>
154 public Func<IContext, object> ScopeCallback
155 {
156 get
157 {
158 return this.BindingConfiguration.ScopeCallback;
159 }
160 set
161 {
162 this.BindingConfiguration.ScopeCallback = value;
163 }
164 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
165
166 /// <summary>
167 /// Gets the parameters defined for the binding.
168 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
169 /// <value></value>
170 public ICollection<IParameter> Parameters
171 {
172 get
173 {
174 return this.BindingConfiguration.Parameters;
175 }
176 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
177
178 /// <summary>
179 /// Gets the actions that should be called after instances are activated via the binding.
180 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
181 /// <value></value>
182 public ICollection<Action<IContext, object>> ActivationActions
183 {
184 get
185 {
186 return this.BindingConfiguration.ActivationActions;
187 }
188 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
189
190 /// <summary>
191 /// Gets the actions that should be called before instances are deactivated via the binding.
192 /// </summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
193 /// <value></value>
194 public ICollection<Action<IContext, object>> DeactivationActions
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
195 {
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
196 get
197 {
198 return this.BindingConfiguration.DeactivationActions;
199 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
200 }
201
202 /// <summary>
203 /// Gets the provider for the binding.
204 /// </summary>
205 /// <param name="context">The context.</param>
206 /// <returns>The provider to use.</returns>
207 public IProvider GetProvider(IContext context)
208 {
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
209 return this.BindingConfiguration.GetProvider(context);
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
210 }
211
212 /// <summary>
213 /// Gets the scope for the binding, if any.
214 /// </summary>
215 /// <param name="context">The context.</param>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
216 /// <returns>
217 /// The object that will act as the scope, or <see langword="null"/> if the service is transient.
218 /// </returns>
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
219 public object GetScope(IContext context)
220 {
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
221 return this.BindingConfiguration.GetScope(context);
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
222 }
223
224 /// <summary>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
225 /// Determines whether the specified request satisfies the condition defined on the binding,
226 /// if one was defined.
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
227 /// </summary>
228 /// <param name="request">The request.</param>
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
229 /// <returns>
230 /// <c>True</c> if the request satisfies the condition; otherwise <c>false</c>.
231 /// </returns>
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
232 public bool Matches(IRequest request)
233 {
d060153 @remogloor - Added support for returning the same instance for two interfaces (I…
remogloor authored
234 return this.BindingConfiguration.Matches(request);
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
235 }
d3ca0c5 Removed ISelector from ReadonlyKernel
Patrick Ineichen authored
236
237 /// <summary>
238 /// Gets or sets the InitizalizeProviderCallback action
239 /// </summary>
240 public Action<ISelector> InitializeProviderCallback
241 {
242 get
243 {
244 return this.BindingConfiguration.InitializeProviderCallback;
245 }
246
247 set
248 {
249 this.BindingConfiguration.InitializeProviderCallback = value;
250 }
251 }
1a213cc @remogloor Replaced tabs by 4 spaces to get a bit more style cop compliant.
remogloor authored
252 }
e22ce49 Moved Ninject2 experiment into repository, still very unstable
nkohari authored
253 }
Something went wrong with that request. Please try again.