How to use BindingConfiguration class of Telerik.JustMock.AutoMock.Ninject.Planning.Bindings package

Best JustMockLite code snippet using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings.BindingConfiguration

Run JustMockLite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

IBinding.cs

Source: IBinding.cs Github

copy
1#region License
2// 
3// Author: Nate Kohari <[email protected]>
4// Copyright (c) 2007-2010, Enkari, Ltd.
5// 
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.
8// 
9#endregion
10#region Using Directives
11using System;
12using System.Collections.Generic;
13using Telerik.JustMock.AutoMock.Ninject.Activation;
14using Telerik.JustMock.AutoMock.Ninject.Parameters;
15#endregion
16
17namespace Telerik.JustMock.AutoMock.Ninject.Planning.Bindings
18{
19    /// <summary>
20    /// Contains information about a service registration.
21    /// </summary>
22    public interface IBinding : IBindingConfiguration
23    {
24        /// <summary>
25        /// Gets the binding configuration.
26        /// </summary>
27        /// <value>The binding configuration.</value>
28        IBindingConfiguration BindingConfiguration { get; }
29
30        /// <summary>
31        /// Gets the service type that is controlled by the binding.
32        /// </summary>
33        Type Service { get; }
34    }
35}
Full Screen

BindingRoot.cs

Source: BindingRoot.cs Github

copy
1//-------------------------------------------------------------------------------
2// <copyright file="BindingRoot.cs" company="Ninject Project Contributors">
3//   Copyright (c) 2007-2009, Enkari, Ltd.
4//   Copyright (c) 2009-2011 Ninject Project Contributors
5//   Authors: Nate Kohari ([email protected])
6//            Remo Gloor ([email protected])
7//           
8//   Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
9//   you may not use this file except in compliance with one of the Licenses.
10//   You may obtain a copy of the License at
11//
12//       http://www.apache.org/licenses/LICENSE-2.0
13//   or
14//       http://www.microsoft.com/opensource/licenses.mspx
15//
16//   Unless required by applicable law or agreed to in writing, software
17//   distributed under the License is distributed on an "AS IS" BASIS,
18//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19//   See the License for the specific language governing permissions and
20//   limitations under the License.
21// </copyright>
22//-------------------------------------------------------------------------------
23
24namespace Telerik.JustMock.AutoMock.Ninject.Syntax
25{
26    using System;
27    using System.Linq;
28
29    using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
30    using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal;
31    using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
32    using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
33
34    /// <summary>
35    /// Provides a path to register bindings.
36    /// </summary>
37    public abstract class BindingRoot : DisposableObject, IBindingRoot
38    {
39        /// <summary>
40        /// Gets the kernel.
41        /// </summary>
42        /// <value>The kernel.</value>
43        protected abstract IKernel KernelInstance { get; }
44
45        /// <summary>
46        /// Declares a binding for the specified service.
47        /// </summary>
48        /// <typeparam name="T">The service to bind.</typeparam>
49        /// <returns>The fluent syntax</returns>
50        public IBindingToSyntax<T> Bind<T>()
51        {
52            Type service = typeof(T);
53
54            var binding = new Binding(service);
55            this.AddBinding(binding);
56
57            return new BindingBuilder<T>(binding, this.KernelInstance, service.Format());
58        }
59
60        /// <summary>
61        /// Declares a binding for the specified service.
62        /// </summary>
63        /// <typeparam name="T1">The first service to bind.</typeparam>
64        /// <typeparam name="T2">The second service to bind.</typeparam>
65        /// <returns>The fluent syntax</returns>
66        public IBindingToSyntax<T1, T2> Bind<T1, T2>()
67        {
68            var firstBinding = new Binding(typeof(T1));
69            this.AddBinding(firstBinding);
70            this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
71            var servceNames = new[] { typeof(T1).Format(), typeof(T2).Format() };
72
73            return new BindingBuilder<T1, T2>(firstBinding.BindingConfiguration, this.KernelInstance, string.Join(", ", servceNames));
74        }
75
76        /// <summary>
77        /// Declares a binding for the specified service.
78        /// </summary>
79        /// <typeparam name="T1">The first service to bind.</typeparam>
80        /// <typeparam name="T2">The second service to bind.</typeparam>
81        /// <typeparam name="T3">The third service to bind.</typeparam>
82        /// <returns>The fluent syntax</returns>
83        public IBindingToSyntax<T1, T2, T3> Bind<T1, T2, T3>()
84        {
85            var firstBinding = new Binding(typeof(T1));
86            this.AddBinding(firstBinding);
87            this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
88            this.AddBinding(new Binding(typeof(T3), firstBinding.BindingConfiguration));
89            var servceNames = new[] { typeof(T1).Format(), typeof(T2).Format(), typeof(T3).Format() };
90
91            return new BindingBuilder<T1, T2, T3>(firstBinding.BindingConfiguration, this.KernelInstance, string.Join(", ", servceNames));
92        }
93
94        /// <summary>
95        /// Declares a binding for the specified service.
96        /// </summary>
97        /// <typeparam name="T1">The first service to bind.</typeparam>
98        /// <typeparam name="T2">The second service to bind.</typeparam>
99        /// <typeparam name="T3">The third service to bind.</typeparam>
100        /// <typeparam name="T4">The fourth service to bind.</typeparam>
101        /// <returns>The fluent syntax</returns>
102        public IBindingToSyntax<T1, T2, T3, T4> Bind<T1, T2, T3, T4>()
103        {
104            var firstBinding = new Binding(typeof(T1));
105            this.AddBinding(firstBinding);
106            this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
107            this.AddBinding(new Binding(typeof(T3), firstBinding.BindingConfiguration));
108            this.AddBinding(new Binding(typeof(T4), firstBinding.BindingConfiguration));
109            var servceNames = new[] { typeof(T1).Format(), typeof(T2).Format(), typeof(T3).Format(), typeof(T4).Format() };
110
111            return new BindingBuilder<T1, T2, T3, T4>(firstBinding.BindingConfiguration, this.KernelInstance, string.Join(", ", servceNames));
112        }
113
114        /// <summary>
115        /// Declares a binding for the specified service.
116        /// </summary>
117        /// <param name="services">The services to bind.</param>
118        /// <returns>The fluent syntax</returns>
119        public IBindingToSyntax<object> Bind(params Type[] services)
120        {
121            Ensure.ArgumentNotNull(services, "service");
122            if (services.Length == 0)
123            {
124                throw new ArgumentException("The services must contain at least one type", "services");                
125            }
126
127            var firstBinding = new Binding(services[0]);
128            this.AddBinding(firstBinding);
129
130            foreach (var service in services.Skip(1))
131            {
132                this.AddBinding(new Binding(service, firstBinding.BindingConfiguration));                
133            }
134
135            return new BindingBuilder<object>(firstBinding, this.KernelInstance, string.Join(", ", services.Select(service => service.Format()).ToArray()));
136        }
137
138        /// <summary>
139        /// Unregisters all bindings for the specified service.
140        /// </summary>
141        /// <typeparam name="T">The service to unbind.</typeparam>
142        public void Unbind<T>()
143        {
144            Unbind(typeof(T));
145        }
146
147        /// <summary>
148        /// Unregisters all bindings for the specified service.
149        /// </summary>
150        /// <param name="service">The service to unbind.</param>
151        public abstract void Unbind(Type service);
152
153        /// <summary>
154        /// Removes any existing bindings for the specified service, and declares a new one.
155        /// </summary>
156        /// <typeparam name="T1">The first service to re-bind.</typeparam>
157        /// <returns>The fluent syntax</returns>
158        public IBindingToSyntax<T1> Rebind<T1>()
159        {
160            Unbind<T1>();
161            return Bind<T1>();
162        }
163
164        /// <summary>
165        /// Removes any existing bindings for the specified services, and declares a new one.
166        /// </summary>
167        /// <typeparam name="T1">The first service to re-bind.</typeparam>
168        /// <typeparam name="T2">The second service to re-bind.</typeparam>
169        /// <returns>The fluent syntax.</returns>
170        public IBindingToSyntax<T1, T2> Rebind<T1, T2>()
171        {
172            Unbind<T1>();
173            Unbind<T2>();
174            return Bind<T1, T2>();
175        }
176
177        /// <summary>
178        /// Removes any existing bindings for the specified services, and declares a new one.
179        /// </summary>
180        /// <typeparam name="T1">The first service to re-bind.</typeparam>
181        /// <typeparam name="T2">The second service to re-bind.</typeparam>
182        /// <typeparam name="T3">The third service to re-bind.</typeparam>
183        /// <returns>The fluent syntax.</returns>
184        public IBindingToSyntax<T1, T2, T3> Rebind<T1, T2, T3>()
185        {
186            Unbind<T1>();
187            Unbind<T2>();
188            Unbind<T3>();
189            return Bind<T1, T2, T3>();
190        }
191
192        /// <summary>
193        /// Removes any existing bindings for the specified services, and declares a new one.
194        /// </summary>
195        /// <typeparam name="T1">The first service to re-bind.</typeparam>
196        /// <typeparam name="T2">The second service to re-bind.</typeparam>
197        /// <typeparam name="T3">The third service to re-bind.</typeparam>
198        /// <typeparam name="T4">The fourth service to re-bind.</typeparam>
199        /// <returns>The fluent syntax.</returns>
200        public IBindingToSyntax<T1, T2, T3, T4> Rebind<T1, T2, T3, T4>()
201        {
202            Unbind<T1>();
203            Unbind<T2>();
204            Unbind<T3>();
205            Unbind<T4>();
206            return Bind<T1, T2, T3, T4>();
207        }
208
209        /// <summary>
210        /// Removes any existing bindings for the specified service, and declares a new one.
211        /// </summary>
212        /// <param name="services">The services to re-bind.</param>
213        /// <returns>The fluent syntax</returns>
214        public IBindingToSyntax<object> Rebind(params Type[] services)
215        {
216            foreach (var service in services)
217            {
218                Unbind(service);                
219            }
220
221            return Bind(services);
222        }
223
224        /// <summary>
225        /// Registers the specified binding.
226        /// </summary>
227        /// <param name="binding">The binding to add.</param>
228        public abstract void AddBinding(IBinding binding);
229
230        /// <summary>
231        /// Unregisters the specified binding.
232        /// </summary>
233        /// <param name="binding">The binding to remove.</param>
234        public abstract void RemoveBinding(IBinding binding);
235    }
236}
Full Screen

Binding.cs

Source: Binding.cs Github

copy
1#region License
2// 
3// Author: Nate Kohari <[email protected]>
4// Copyright (c) 2007-2010, Enkari, Ltd.
5// 
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.
8// 
9#endregion
10#region Using Directives
11using System;
12using System.Collections.Generic;
13using Telerik.JustMock.AutoMock.Ninject.Activation;
14using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
15using Telerik.JustMock.AutoMock.Ninject.Parameters;
16#endregion
17
18namespace Telerik.JustMock.AutoMock.Ninject.Planning.Bindings
19{
20    /// <summary>
21    /// Contains information about a service registration.
22    /// </summary>
23    public class Binding : IBinding
24    {
25        /// <summary>
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;
34            this.BindingConfiguration = new BindingConfiguration();
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>
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>
65        /// <value></value>
66        public IBindingMetadata Metadata
67        {
68            get
69            {
70                return this.BindingConfiguration.Metadata;
71            }
72        }
73
74        /// <summary>
75        /// Gets or sets the type of target for the binding.
76        /// </summary>
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        }
90
91        /// <summary>
92        /// Gets or sets a value indicating whether the binding was implicitly registered.
93        /// </summary>
94        /// <value></value>
95        public bool IsImplicit
96        {
97            get
98            {
99                return this.BindingConfiguration.IsImplicit;
100            }
101
102            set
103            {
104                this.BindingConfiguration.IsImplicit = value;
105            }
106        }
107
108        /// <summary>
109        /// Gets a value indicating whether the binding has a condition associated with it.
110        /// </summary>
111        /// <value></value>
112        public bool IsConditional
113        {
114            get
115            {
116                return this.BindingConfiguration.IsConditional;
117            }
118        }
119
120        /// <summary>
121        /// Gets or sets the condition defined for the binding.
122        /// </summary>
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        }
135
136        /// <summary>
137        /// Gets or sets the callback that returns the provider that should be used by the binding.
138        /// </summary>
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        }
152
153        /// <summary>
154        /// Gets or sets the callback that returns the object that will act as the binding's scope.
155        /// </summary>
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        }
168
169        /// <summary>
170        /// Gets the parameters defined for the binding.
171        /// </summary>
172        /// <value></value>
173        public ICollection<IParameter> Parameters
174        {
175            get
176            {
177                return this.BindingConfiguration.Parameters;
178            }
179        }
180
181        /// <summary>
182        /// Gets the actions that should be called after instances are activated via the binding.
183        /// </summary>
184        /// <value></value>
185        public ICollection<Action<IContext, object>> ActivationActions
186        {
187            get
188            {
189                return this.BindingConfiguration.ActivationActions;
190            }
191        }
192
193        /// <summary>
194        /// Gets the actions that should be called before instances are deactivated via the binding.
195        /// </summary>
196        /// <value></value>
197        public ICollection<Action<IContext, object>> DeactivationActions
198        {
199            get
200            {
201                return this.BindingConfiguration.DeactivationActions;
202            }
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        {
212            return this.BindingConfiguration.GetProvider(context);
213        }
214
215        /// <summary>
216        /// Gets the scope for the binding, if any.
217        /// </summary>
218        /// <param name="context">The context.</param>
219        /// <returns>
220        /// The object that will act as the scope, or <see langword="null"/> if the service is transient.
221        /// </returns>
222        public object GetScope(IContext context)
223        {
224            return this.BindingConfiguration.GetScope(context);
225        }
226
227        /// <summary>
228        /// Determines whether the specified request satisfies the condition defined on the binding,
229        /// if one was defined.
230        /// </summary>
231        /// <param name="request">The request.</param>
232        /// <returns>
233        ///     <c>True</c> if the request satisfies the condition; otherwise <c>false</c>.
234        /// </returns>
235        public bool Matches(IRequest request)
236        {
237            return this.BindingConfiguration.Matches(request);
238        }
239    }
240}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in BindingConfiguration

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)