How to use Pipeline class of Telerik.JustMock.AutoMock.Ninject.Activation package

Best JustMockLite code snippet using Telerik.JustMock.AutoMock.Ninject.Activation.Pipeline

Run JustMockLite automation tests on LambdaTest cloud grid

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

Pipeline.cs

Source: Pipeline.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
11namespace Telerik.JustMock.AutoMock.Ninject.Activation
12{
13    using System.Collections.Generic;
14    using System.Linq;
15    using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
16    using Telerik.JustMock.AutoMock.Ninject.Activation.Strategies;
17    using Telerik.JustMock.AutoMock.Ninject.Components;
18    using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
19    using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Language;
20
21    /// <summary>
22    /// Drives the activation (injection, etc.) of an instance.
23    /// </summary>
24    public class Pipeline : NinjectComponent, IPipeline
25    {
26        /// <summary>
27        /// The activation cache.
28        /// </summary>
29        private readonly IActivationCache activationCache;
30
31        /// <summary>
32        /// Initializes a new instance of the <see cref="Pipeline"/> class.
33        /// </summary>
34        /// <param name="strategies">The strategies to execute during activation and deactivation.</param>
35        /// <param name="activationCache">The activation cache.</param>
36        public Pipeline(IEnumerable<IActivationStrategy> strategies, IActivationCache activationCache)
37        {
38            Ensure.ArgumentNotNull(strategies, "strategies");
39            this.Strategies = strategies.ToList();
40            this.activationCache = activationCache;
41        }
42
43        /// <summary>
44        /// Gets the strategies that contribute to the activation and deactivation processes.
45        /// </summary>
46        public IList<IActivationStrategy> Strategies { get; private set; }
47
48        /// <summary>
49        /// Activates the instance in the specified context.
50        /// </summary>
51        /// <param name="context">The context.</param>
52        /// <param name="reference">The instance reference.</param>
53        public void Activate(IContext context, InstanceReference reference)
54        {
55            Ensure.ArgumentNotNull(context, "context");
56            if (!this.activationCache.IsActivated(reference.Instance))
57            {
58                this.Strategies.Map(s => s.Activate(context, reference));
59            }
60        }
61
62        /// <summary>
63        /// Deactivates the instance in the specified context.
64        /// </summary>
65        /// <param name="context">The context.</param>
66        /// <param name="reference">The instance reference.</param>
67        public void Deactivate(IContext context, InstanceReference reference)
68        {
69            Ensure.ArgumentNotNull(context, "context");
70            if (!this.activationCache.IsDeactivated(reference.Instance))
71            {
72                this.Strategies.Map(s => s.Deactivate(context, reference));
73            }
74        }
75    }
76}
Full Screen

Context.cs

Source: Context.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 System.Linq;
14using Telerik.JustMock.AutoMock.Ninject.Activation.Caching;
15using Telerik.JustMock.AutoMock.Ninject.Infrastructure;
16using Telerik.JustMock.AutoMock.Ninject.Infrastructure.Introspection;
17using Telerik.JustMock.AutoMock.Ninject.Parameters;
18using Telerik.JustMock.AutoMock.Ninject.Planning;
19using Telerik.JustMock.AutoMock.Ninject.Planning.Bindings;
20#endregion
21
22namespace Telerik.JustMock.AutoMock.Ninject.Activation
23{
24    /// <summary>
25    /// Contains information about the activation of a single instance.
26    /// </summary>
27    public class Context : IContext
28    {
29        private WeakReference cachedScope;
30
31        /// <summary>
32        /// Gets the kernel that is driving the activation.
33        /// </summary>
34        public IKernel Kernel { get; set; }
35
36        /// <summary>
37        /// Gets the request.
38        /// </summary>
39        public IRequest Request { get; set; }
40
41        /// <summary>
42        /// Gets the binding.
43        /// </summary>
44        public IBinding Binding { get; set; }
45
46        /// <summary>
47        /// Gets or sets the activation plan.
48        /// </summary>
49        public IPlan Plan { get; set; }
50
51        /// <summary>
52        /// Gets the parameters that were passed to manipulate the activation process.
53        /// </summary>
54        public ICollection<IParameter> Parameters { get; set; }
55
56        /// <summary>
57        /// Gets the generic arguments for the request, if any.
58        /// </summary>
59        public Type[] GenericArguments { get; private set; }
60
61        /// <summary>
62        /// Gets a value indicating whether the request involves inferred generic arguments.
63        /// </summary>
64        public bool HasInferredGenericArguments { get; private set; }
65
66        /// <summary>
67        /// Gets or sets the cache component.
68        /// </summary>
69        public ICache Cache { get; private set; }
70
71        /// <summary>
72        /// Gets or sets the planner component.
73        /// </summary>
74        public IPlanner Planner { get; private set; }
75
76        /// <summary>
77        /// Gets or sets the pipeline component.
78        /// </summary>
79        public IPipeline Pipeline { get; private set; }
80
81        /// <summary>
82        /// Initializes a new instance of the <see cref="Context"/> class.
83        /// </summary>
84        /// <param name="kernel">The kernel managing the resolution.</param>
85        /// <param name="request">The context's request.</param>
86        /// <param name="binding">The context's binding.</param>
87        /// <param name="cache">The cache component.</param>
88        /// <param name="planner">The planner component.</param>
89        /// <param name="pipeline">The pipeline component.</param>
90        public Context(IKernel kernel, IRequest request, IBinding binding, ICache cache, IPlanner planner, IPipeline pipeline)
91        {
92            Ensure.ArgumentNotNull(kernel, "kernel");
93            Ensure.ArgumentNotNull(request, "request");
94            Ensure.ArgumentNotNull(binding, "binding");
95            Ensure.ArgumentNotNull(cache, "cache");
96            Ensure.ArgumentNotNull(planner, "planner");
97            Ensure.ArgumentNotNull(pipeline, "pipeline");
98
99            Kernel = kernel;
100            Request = request;
101            Binding = binding;
102            Parameters = request.Parameters.Union(binding.Parameters).ToList();
103
104            Cache = cache;
105            Planner = planner;
106            Pipeline = pipeline;
107
108            if (binding.Service.IsGenericTypeDefinition)
109            {
110                HasInferredGenericArguments = true;
111                GenericArguments = request.Service.GetGenericArguments();
112            }
113        }
114
115        /// <summary>
116        /// Gets the scope for the context that "owns" the instance activated therein.
117        /// </summary>
118        /// <returns>The object that acts as the scope.</returns>
119        public object GetScope()
120        {
121            if (this.cachedScope == null)
122            {
123                var scope = this.Request.GetScope() ?? this.Binding.GetScope(this);
124                this.cachedScope = new WeakReference(scope);
125            }
126            
127            return this.cachedScope.Target;
128        }
129
130        /// <summary>
131        /// Gets the provider that should be used to create the instance for this context.
132        /// </summary>
133        /// <returns>The provider that should be used.</returns>
134        public IProvider GetProvider()
135        {
136            return Binding.GetProvider(this);
137        }
138
139        /// <summary>
140        /// Resolves the instance associated with this hook.
141        /// </summary>
142        /// <returns>The resolved instance.</returns>
143        public object Resolve()
144        {
145            lock (Binding)
146            {
147                if (Request.ActiveBindings.Contains(Binding))
148                    throw new ActivationException(ExceptionFormatter.CyclicalDependenciesDetected(this));
149
150                var cachedInstance = Cache.TryGet(this);
151
152                if (cachedInstance != null)
153                    return cachedInstance;
154
155                Request.ActiveBindings.Push(Binding);
156
157                var reference = new InstanceReference { Instance = GetProvider().Create(this) };
158
159                Request.ActiveBindings.Pop();
160
161                if (reference.Instance == null)
162                {
163                    if (!this.Kernel.Settings.AllowNullInjection)
164                    {
165                        throw new ActivationException(ExceptionFormatter.ProviderReturnedNull(this));
166                    }
167
168                    if (this.Plan == null)
169                    {
170                        this.Plan = this.Planner.GetPlan(this.Request.Service);
171                    }
172
173                    return null;
174                }
175
176                if (GetScope() != null)
177                    Cache.Remember(this, reference);
178
179                if (Plan == null)
180                    Plan = Planner.GetPlan(reference.Instance.GetType());
181
182                Pipeline.Activate(this, reference);
183
184                return reference.Instance;
185            }
186        }
187    }
188}
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 Pipeline

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)