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

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

Run JustMockLite automation tests on LambdaTest cloud grid

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

DefaultValueBindingResolver.cs

Source: DefaultValueBindingResolver.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
11
12using System;
13using System.Collections.Generic;
14using System.Linq;
15using Telerik.JustMock.AutoMock.Ninject.Activation;
16using Telerik.JustMock.AutoMock.Ninject.Components;
17using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
18using Telerik.JustMock.AutoMock.Ninject.Planning.Targets;
19
20#endregion
21
22namespace Telerik.JustMock.AutoMock.Ninject.Planning.Bindings.Resolvers
23{
24
25    ///<summary>
26    ///</summary>
27    public class DefaultValueBindingResolver : NinjectComponent, IMissingBindingResolver
28    {
29        /// <summary>
30        /// Returns any bindings from the specified collection that match the specified service.
31        /// </summary>
32        /// <param name="bindings">The multimap of all registered bindings.</param>
33        /// <param name="request">The service in question.</param>
34        /// <returns>The series of matching bindings.</returns>
35        public IEnumerable<IBinding> Resolve(Multimap<Type, IBinding> bindings, IRequest request)
36        {
37            var service = request.Service;
38            return HasDefaultValue(request.Target)
39                       ? new[]
40                             {
41                                 new Binding(service)
42                                     {
43                                         Condition = r => HasDefaultValue(r.Target),
44                                         ProviderCallback = _ => new DefaultParameterValueProvider(service),
45                                     }
46                             }
47                       : Enumerable.Empty<IBinding>();
48        }
49
50        private static bool HasDefaultValue(ITarget target)
51        {
52            return target != null && target.HasDefaultValue;
53        }
54
55        private class DefaultParameterValueProvider : IProvider
56        {
57            public DefaultParameterValueProvider(Type type)
58            {
59                Type = type;
60            }
61
62            public Type Type { get; private set; }
63
64            public object Create(IContext context)
65            {
66                var target = context.Request.Target;
67                return (target == null) ? null : target.DefaultValue;
68            }
69        }
70    }
71}
Full Screen

StandardKernel.cs

Source: StandardKernel.cs Github

copy
1//-------------------------------------------------------------------------------
2// <copyright file="StandardKernel.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
25{
26    using System;
27    using Telerik.JustMock.AutoMock.Ninject.Activation;
28    using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
29    using Telerik.JustMock.AutoMock.Ninject.Activation.Strategies;
30    using Telerik.JustMock.AutoMock.Ninject.Components;
31    using Telerik.JustMock.AutoMock.Ninject.Injection;
32    using Telerik.JustMock.AutoMock.Ninject.Modules;
33    using Telerik.JustMock.AutoMock.Ninject.Planning;
34    using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings.Resolvers;
35    using Telerik.JustMock.AutoMock.Ninject.Planning.Strategies;
36    using Telerik.JustMock.AutoMock.Ninject.Selection;
37    using Telerik.JustMock.AutoMock.Ninject.Selection.Heuristics;
38
39    /// <summary>
40    /// The standard implementation of a kernel.
41    /// </summary>
42    public class StandardKernel : KernelBase
43    {
44        /// <summary>
45        /// Initializes a new instance of the <see cref="StandardKernel"/> class.
46        /// </summary>
47        /// <param name="modules">The modules to load into the kernel.</param>
48        public StandardKernel(params INinjectModule[] modules) : base(modules)
49        {
50        }
51
52        /// <summary>
53        /// Initializes a new instance of the <see cref="StandardKernel"/> class.
54        /// </summary>
55        /// <param name="settings">The configuration to use.</param>
56        /// <param name="modules">The modules to load into the kernel.</param>
57        public StandardKernel(INinjectSettings settings, params INinjectModule[] modules) : base(settings, modules)
58        {
59        }
60
61        /// <summary>
62        /// Gets the kernel.
63        /// </summary>
64        /// <value>The kernel.</value>
65        protected override IKernel KernelInstance
66        {
67            get
68            {
69                return this;
70            }
71        }
72
73        protected virtual bool ShouldAddComponent(Type component, Type implementation)
74        {
75            return true;
76        }
77
78        private void AddComponent<TComponent, TImplementation>()
79            where TComponent : INinjectComponent
80            where TImplementation : TComponent, INinjectComponent
81        {
82            if (ShouldAddComponent(typeof(TComponent), typeof(TImplementation)))
83            {
84                Components.Add<TComponent, TImplementation>();
85            }
86        }
87        
88        /// <summary>
89        /// Adds components to the kernel during startup.
90        /// </summary>
91        protected override void AddComponents()
92        {
93            AddComponent<IPlanner, Planner>();
94            AddComponent<IPlanningStrategy, ConstructorReflectionStrategy>();
95            AddComponent<IPlanningStrategy, PropertyReflectionStrategy>();
96            AddComponent<IPlanningStrategy, MethodReflectionStrategy>();
97
98            AddComponent<ISelector, Selector>();
99            AddComponent<IConstructorScorer, StandardConstructorScorer>();
100            AddComponent<IInjectionHeuristic, StandardInjectionHeuristic>();
101
102            AddComponent<IPipeline, Pipeline>();
103            if (!Settings.ActivationCacheDisabled)
104            {
105                AddComponent<IActivationStrategy, ActivationCacheStrategy>();
106            }
107
108            AddComponent<IActivationStrategy, PropertyInjectionStrategy>();
109            AddComponent<IActivationStrategy, MethodInjectionStrategy>();
110            AddComponent<IActivationStrategy, InitializableStrategy>();
111            AddComponent<IActivationStrategy, StartableStrategy>();
112            AddComponent<IActivationStrategy, BindingActionStrategy>();
113            AddComponent<IActivationStrategy, DisposableStrategy>();
114
115            AddComponent<IBindingResolver, StandardBindingResolver>();
116            AddComponent<IBindingResolver, OpenGenericBindingResolver>();
117
118            AddComponent<IMissingBindingResolver, DefaultValueBindingResolver>();
119            AddComponent<IMissingBindingResolver, SelfBindingResolver>();
120
121#if !NO_LCG
122            if (!Settings.UseReflectionBasedInjection)
123            {
124                AddComponent<IInjectorFactory, DynamicMethodInjectorFactory>();
125            }
126            else
127#endif
128            {
129                AddComponent<IInjectorFactory, ReflectionInjectorFactory>();
130            }
131
132            AddComponent<ICache, Cache>();
133            AddComponent<IActivationCache, ActivationCache>();
134            AddComponent<ICachePruner, GarbageCollectionCachePruner>();
135
136#if !NO_ASSEMBLY_SCANNING
137            AddComponent<IModuleLoader, ModuleLoader>();
138            AddComponent<IModuleLoaderPlugin, CompiledModuleLoaderPlugin>();
139            AddComponent<IAssemblyNameRetriever, AssemblyNameRetriever>();
140#endif
141        }
142    }
143}
144
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 DefaultValueBindingResolver

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)