Skip to content
This repository
Newer
Older
100644 240 lines (218 sloc) 7.153 kb
6e1e0a16 »
2009-03-23 Updated licensing terms to reflect dual-license with Ms-PL
1 #region License
2 //
fe035089 »
2009-03-07 Merged from fork
3 // Author: Nate Kohari <nate@enkari.com>
5b24b7a8 »
2010-02-19 Updated copyright, fixed line endings
4 // Copyright (c) 2007-2010, Enkari, Ltd.
fe035089 »
2009-03-07 Merged from fork
5 //
6e1e0a16 »
2009-03-23 Updated licensing terms to reflect dual-license with Ms-PL
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.
fe035089 »
2009-03-07 Merged from fork
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 {
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
20 /// <summary>
21 /// Contains information about a service registration.
22 /// </summary>
23 public class Binding : IBinding
24 {
25 /// <summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
26 /// Initializes a new instance of the <see cref="Binding"/> class.
27 /// </summary>
28 /// <param name="service">The service that is controlled by the binding.</param>
29 public Binding(Type service)
30 {
31 Ensure.ArgumentNotNull(service, "service");
32
33 this.Service = service;
b60dcc27 »
2012-05-23 Simplify Default Scope implementation
34 this.BindingConfiguration = new BindingConfiguration();
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
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 Ensure.ArgumentNotNull(service, "service");
45 Ensure.ArgumentNotNull(configuration, "configuration");
46
47 this.Service = service;
48 this.BindingConfiguration = configuration;
49 }
50
51 /// <summary>
52 /// Gets or sets the binding configuration.
53 /// </summary>
54 /// <value>The binding configuration.</value>
55 public IBindingConfiguration BindingConfiguration { get; private set; }
56
57 /// <summary>
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
58 /// Gets the service type that is controlled by the binding.
59 /// </summary>
60 public Type Service { get; private set; }
61
62 /// <summary>
63 /// Gets the binding's metadata.
64 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
65 /// <value></value>
66 public IBindingMetadata Metadata
67 {
68 get
69 {
70 return this.BindingConfiguration.Metadata;
71 }
72 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
73
74 /// <summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
75 /// Gets or sets the type of target for the binding.
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
76 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
77 /// <value></value>
78 public BindingTarget Target
79 {
80 get
81 {
82 return this.BindingConfiguration.Target;
83 }
84
85 set
86 {
87 this.BindingConfiguration.Target = value;
88 }
89 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
90
91 /// <summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
92 /// Gets or sets a value indicating whether the binding was implicitly registered.
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
93 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
94 /// <value></value>
95 public bool IsImplicit
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
96 {
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
97 get
98 {
99 return this.BindingConfiguration.IsImplicit;
100 }
101
102 set
103 {
104 this.BindingConfiguration.IsImplicit = value;
105 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
106 }
107
108 /// <summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
109 /// Gets a value indicating whether the binding has a condition associated with it.
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
110 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
111 /// <value></value>
112 public bool IsConditional
113 {
114 get
115 {
116 return this.BindingConfiguration.IsConditional;
117 }
118 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
119
120 /// <summary>
121 /// Gets or sets the condition defined for the binding.
122 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
123 /// <value></value>
124 public Func<IRequest, bool> Condition
125 {
126 get
127 {
128 return this.BindingConfiguration.Condition;
129 }
130 set
131 {
132 this.BindingConfiguration.Condition = value;
133 }
134 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
135
136 /// <summary>
137 /// Gets or sets the callback that returns the provider that should be used by the binding.
138 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
139 /// <value></value>
140 public Func<IContext, IProvider> ProviderCallback
141 {
142 get
143 {
144 return this.BindingConfiguration.ProviderCallback;
145 }
146
147 set
148 {
149 this.BindingConfiguration.ProviderCallback = value;
150 }
151 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
152
153 /// <summary>
154 /// Gets or sets the callback that returns the object that will act as the binding's scope.
155 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
156 /// <value></value>
157 public Func<IContext, object> ScopeCallback
158 {
159 get
160 {
161 return this.BindingConfiguration.ScopeCallback;
162 }
163 set
164 {
165 this.BindingConfiguration.ScopeCallback = value;
166 }
167 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
168
169 /// <summary>
170 /// Gets the parameters defined for the binding.
171 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
172 /// <value></value>
173 public ICollection<IParameter> Parameters
174 {
175 get
176 {
177 return this.BindingConfiguration.Parameters;
178 }
179 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
180
181 /// <summary>
182 /// Gets the actions that should be called after instances are activated via the binding.
183 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
184 /// <value></value>
185 public ICollection<Action<IContext, object>> ActivationActions
186 {
187 get
188 {
189 return this.BindingConfiguration.ActivationActions;
190 }
191 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
192
193 /// <summary>
194 /// Gets the actions that should be called before instances are deactivated via the binding.
195 /// </summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
196 /// <value></value>
197 public ICollection<Action<IContext, object>> DeactivationActions
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
198 {
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
199 get
200 {
201 return this.BindingConfiguration.DeactivationActions;
202 }
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
203 }
204
205 /// <summary>
206 /// Gets the provider for the binding.
207 /// </summary>
208 /// <param name="context">The context.</param>
209 /// <returns>The provider to use.</returns>
210 public IProvider GetProvider(IContext context)
211 {
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
212 return this.BindingConfiguration.GetProvider(context);
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
213 }
214
215 /// <summary>
216 /// Gets the scope for the binding, if any.
217 /// </summary>
218 /// <param name="context">The context.</param>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
219 /// <returns>
220 /// The object that will act as the scope, or <see langword="null"/> if the service is transient.
221 /// </returns>
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
222 public object GetScope(IContext context)
223 {
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
224 return this.BindingConfiguration.GetScope(context);
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
225 }
226
227 /// <summary>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
228 /// Determines whether the specified request satisfies the condition defined on the binding,
229 /// if one was defined.
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
230 /// </summary>
231 /// <param name="request">The request.</param>
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
232 /// <returns>
233 /// <c>True</c> if the request satisfies the condition; otherwise <c>false</c>.
234 /// </returns>
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
235 public bool Matches(IRequest request)
236 {
d0601531 »
2011-12-02 - Added support for returning the same instance for two interfaces (I…
237 return this.BindingConfiguration.Matches(request);
1a213cc6 »
2010-08-25 Replaced tabs by 4 spaces to get a bit more style cop compliant.
238 }
239 }
e22ce494 »
2009-02-01 Moved Ninject2 experiment into repository, still very unstable
240 }
Something went wrong with that request. Please try again.