Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyKernel"/> class.
        /// </summary>
        /// <param name="bindings">The preconfigured bindings.</param>
        /// <param name="cache">The <see cref="ICache"/> component.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="scorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="pipeline">The <see cref="IPipeline"/> component.</param>
        /// <param name="bindingPrecedenceComparer">The <see cref="IBindingPrecedenceComparer"/> component.</param>
        /// <param name="bindingResolvers">The binding resolvers.</param>
        /// <param name="missingBindingResolvers">The missng binding resolvers.</param>
        /// <param name="settings">The <see cref="INinjectSettings"/>.</param>
        internal ReadOnlyKernel(
            INinjectSettings settings,
            IDictionary <Type, ICollection <IBinding> > bindings,
            ICache cache,
            IPlanner planner,
            IConstructorScorer scorer,
            IPipeline pipeline,
            IBindingPrecedenceComparer bindingPrecedenceComparer,
            IEnumerable <IBindingResolver> bindingResolvers,
            IEnumerable <IMissingBindingResolver> missingBindingResolvers)
        {
            this.Settings = settings;

            this.bindingResolvers        = bindingResolvers;
            this.missingBindingResolvers = missingBindingResolvers;
            this.cache    = cache;
            this.planner  = planner;
            this.scorer   = scorer;
            this.pipeline = pipeline;
            this.bindingPrecedenceComparer = bindingPrecedenceComparer;

            this.AddReadOnlyKernelBinding <IReadOnlyKernel>(this, bindings);
            this.AddReadOnlyKernelBinding <IResolutionRoot>(this, bindings);

            this.bindings = bindings.Keys.ToDictionary(type => type, type => bindings[type]);
            this.InitializeBindings();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadOnlyKernel"/> class.
        /// </summary>
        /// <param name="settings">The <see cref="INinjectSettings"/>.</param>
        /// <param name="bindings">The preconfigured bindings.</param>
        /// <param name="cache">The <see cref="ICache"/> component.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="pipeline">The <see cref="IPipeline"/> component.</param>
        /// <param name="exceptionFormatter">The <see cref="IExceptionFormatter"/> component.</param>
        /// <param name="bindingPrecedenceComparer">The <see cref="IBindingPrecedenceComparer"/> component.</param>
        /// <param name="bindingResolvers">The binding resolvers.</param>
        /// <param name="missingBindingResolvers">The missing binding resolvers.</param>
        internal ReadOnlyKernel(
            INinjectSettings settings,
            Dictionary <Type, ICollection <IBinding> > bindings,
            ICache cache,
            IPlanner planner,
            IConstructorScorer constructorScorer,
            IPipeline pipeline,
            IExceptionFormatter exceptionFormatter,
            IBindingPrecedenceComparer bindingPrecedenceComparer,
            List <IBindingResolver> bindingResolvers,
            List <IMissingBindingResolver> missingBindingResolvers)
        {
            this.settings                = settings;
            this.bindings                = bindings;
            this.bindingResolvers        = bindingResolvers;
            this.missingBindingResolvers = missingBindingResolvers;
            this.cache                     = cache;
            this.planner                   = planner;
            this.constructorScorer         = constructorScorer;
            this.pipeline                  = pipeline;
            this.exceptionFormatter        = exceptionFormatter;
            this.bindingPrecedenceComparer = bindingPrecedenceComparer;

            this.AddReadOnlyKernelBinding <IReadOnlyKernel>(this, bindings);
            this.AddReadOnlyKernelBinding <IResolutionRoot>(this, bindings);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelfBindingResolver"/> class.
        /// </summary>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        public SelfBindingResolver(IPlanner planner, IConstructorScorer constructorScorer)
        {
            Ensure.ArgumentNotNull(planner, nameof(planner));
            Ensure.ArgumentNotNull(constructorScorer, nameof(constructorScorer));

            this.planner           = planner;
            this.constructorScorer = constructorScorer;
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="constructorScorer">The constructor scorer component.</param>
        public StandardProvider(Type type, IConstructorScorer constructorScorer)
        {
            Contract.Requires(type != null);
            Contract.Requires(constructorScorer != null);

            this.Type = type;
            this.ConstructorScorer = constructorScorer;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="constructorScorer">The constructor scorer.</param>
        /// <param name="injectionHeuristics">The injection heuristics.</param>
        public Selector(IConstructorScorer constructorScorer, IEnumerable<IInjectionHeuristic> injectionHeuristics)
        {
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");
            Ensure.ArgumentNotNull(injectionHeuristics, "injectionHeuristics");

            ConstructorScorer = constructorScorer;
            InjectionHeuristics = injectionHeuristics.ToList();
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelfBindingResolver"/> class.
        /// </summary>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="scorer">The <see cref="IConstructorScorer"/> component.</param>
        public SelfBindingResolver(IPlanner planner, IConstructorScorer scorer)
        {
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(scorer, "scorer");

            this.planner = planner;
            this.scorer  = scorer;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="constructorScorer">The constructor scorer.</param>
        /// <param name="injectionHeuristics">The injection heuristics.</param>
        public Selector(IConstructorScorer constructorScorer, IEnumerable <IInjectionHeuristic> injectionHeuristics)
        {
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");
            Ensure.ArgumentNotNull(injectionHeuristics, "injectionHeuristics");

            ConstructorScorer   = constructorScorer;
            InjectionHeuristics = injectionHeuristics.ToList();
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="constructorScorer">The constructor scorer component.</param>
        public StandardProvider(Type type, IConstructorScorer constructorScorer)
        {
            Contract.Requires(type != null);
            Contract.Requires(constructorScorer != null);

            this.Type = type;
            this.ConstructorScorer = constructorScorer;
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="constructorScorer">The constructor scorer component.</param>
        public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer)
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");

            this.Type              = type;
            this.Planner           = planner;
            this.ConstructorScorer = constructorScorer;
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Selector"/> class.
        /// </summary>
        /// <param name="constructorScorer">The constructor scorer.</param>
        /// <param name="injectionHeuristics">The injection heuristics.</param>
        /// <param name="settings">The ninject settings.</param>
        public Selector(INinjectSettings settings, IConstructorScorer constructorScorer, IEnumerable <IInjectionHeuristic> injectionHeuristics)
        {
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");
            Ensure.ArgumentNotNull(injectionHeuristics, "injectionHeuristics");
            Ensure.ArgumentNotNull(settings, "settings");

            this.constructorScorer   = constructorScorer;
            this.injectionHeuristics = injectionHeuristics.ToList();
            this.settings            = settings;
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardProvider"/> class.
        /// </summary>
        /// <param name="type">The type (or prototype) of instances the provider creates.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="constructorScorer">The constructor scorer component.</param>
        public StandardProvider(Type type, IPlanner planner, IConstructorScorer constructorScorer
            )
        {
            Ensure.ArgumentNotNull(type, "type");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(constructorScorer, "constructorScorer");

            Type = type;
            Planner = planner;
            ConstructorScorer = constructorScorer;
        }
        public void Constructor_ShouldThrowArgumentNullExceptionWhenConstructorScorerIsNull()
        {
            var type    = typeof(Monk);
            var planner = _plannerMock.Object;
            IConstructorScorer constructorScorer = null;

            var actual = Assert.Throws <ArgumentNullException>(() => new StandardProvider(type, planner, constructorScorer));

            Assert.Null(actual.InnerException);
            Assert.Equal(nameof(constructorScorer), actual.ParamName);
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BindingBuilder{T1, T2, T3, T4}"/> class.
 /// </summary>
 /// <param name="bindingConfiguration">The binding to build.</param>
 /// <param name="planner">The <see cref="IPlanner"/> component.</param>
 /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
 /// <param name="serviceNames">The names of the services.</param>
 /// <exception cref="ArgumentNullException"><paramref name="bindingConfiguration"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="planner"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="constructorScorer"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="serviceNames"/> is <see langword="null"/>.</exception>
 public BindingBuilder(
     IBindingConfiguration bindingConfiguration,
     IPlanner planner,
     IConstructorScorer constructorScorer,
     string serviceNames)
     : base(
         bindingConfiguration,
         planner,
         constructorScorer,
         serviceNames)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingBuilder{T1}"/> class.
        /// </summary>
        /// <param name="binding">The binding to build.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="serviceNames">The names of the services.</param>
        public BindingBuilder(
            IBinding binding,
            IPlanner planner,
            IConstructorScorer constructorScorer,
            string serviceNames)
            : base(
                binding.BindingConfiguration,
                planner,
                constructorScorer,
                serviceNames)
        {
            Ensure.ArgumentNotNull(binding, "binding");

            this.Binding = binding;
        }
Example #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingBuilder"/> class.
        /// </summary>
        /// <param name="bindingConfiguration">The binding to build.</param>
        /// <param name="planner">The <see cref="IPlanner"/> component.</param>
        /// <param name="constructorScorer">The <see cref="IConstructorScorer"/> component.</param>
        /// <param name="serviceNames">The names of the services.</param>
        /// <exception cref="ArgumentNullException"><paramref name="bindingConfiguration"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="planner"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="constructorScorer"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="serviceNames"/> is <see langword="null"/>.</exception>
        public BindingBuilder(
            IBindingConfiguration bindingConfiguration,
            IPlanner planner,
            IConstructorScorer constructorScorer,
            string serviceNames)
        {
            Ensure.ArgumentNotNull(bindingConfiguration, nameof(bindingConfiguration));
            Ensure.ArgumentNotNull(planner, nameof(planner));
            Ensure.ArgumentNotNull(constructorScorer, nameof(constructorScorer));
            Ensure.ArgumentNotNull(serviceNames, nameof(serviceNames));

            this.BindingConfiguration = bindingConfiguration;
            this.Planner           = planner;
            this.ConstructorScorer = constructorScorer;
            this.ServiceNames      = serviceNames;
        }
 internal MyReadOnlyKernel(INinjectSettings settings,
                           Dictionary <Type, ICollection <IBinding> > bindings,
                           ICache cache,
                           IPlanner planner,
                           IConstructorScorer constructorScorer,
                           IPipeline pipeline,
                           IBindingPrecedenceComparer bindingPrecedenceComparer,
                           IEnumerable <IBindingResolver> bindingResolvers,
                           IEnumerable <IMissingBindingResolver> missingBindingResolvers)
     : base(settings,
            bindings,
            cache,
            planner,
            constructorScorer,
            pipeline,
            bindingPrecedenceComparer,
            bindingResolvers,
            missingBindingResolvers)
 {
 }
Example #17
0
        /// <summary>
        /// Gets a callback that creates an instance of the <see cref="StandardProvider"/>
        /// for the specified type.
        /// </summary>
        /// <param name="prototype">The prototype the provider instance will create.</param>
        /// <param name="planner">The planner component.</param>
        /// <param name="scorer">The constructor scorer.</param>
        /// <returns>The created callback.</returns>
        public static Func <IContext, IProvider> GetCreationCallback(Type prototype, IPlanner planner, IConstructorScorer scorer)
        {
            Ensure.ArgumentNotNull(prototype, "prototype");
            Ensure.ArgumentNotNull(planner, "planner");
            Ensure.ArgumentNotNull(scorer, "scorer");

            return(ctx => new StandardProvider(prototype, planner, scorer));
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardProvider"/> class.
 /// </summary>
 /// <param name="type">The type (or prototype) of instances the provider creates.</param>
 /// <param name="constructorScorer">The constructor scorer component.</param>
 public StandardProvider(Type type, IConstructorScorer constructorScorer)
 {
     this.Type = type;
     this.ConstructorScorer = constructorScorer;
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardProvider"/> class.
 /// </summary>
 /// <param name="type">The type (or prototype) of instances the provider creates.</param>
 /// <param name="constructorScorer">The constructor scorer component.</param>
 public StandardProvider(Type type, IConstructorScorer constructorScorer)
 {
     this.Type = type;
     this.ConstructorScorer = constructorScorer;
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Selector"/> class.
 /// </summary>
 /// <param name="constructorScorer">The constructor scorer.</param>
 /// <param name="injectionHeuristics">The injection heuristics.</param>
 public Selector(IConstructorScorer constructorScorer, IEnumerable<IInjectionHeuristic> injectionHeuristics)
 {
     this.ConstructorScorer = constructorScorer;
     this.InjectionHeuristics = injectionHeuristics.ToList();
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Selector"/> class.
 /// </summary>
 /// <param name="constructorScorer">The constructor scorer.</param>
 /// <param name="injectionHeuristics">The injection heuristics.</param>
 public Selector(IConstructorScorer constructorScorer, IEnumerable <IInjectionHeuristic> injectionHeuristics)
 {
     this.ConstructorScorer   = constructorScorer;
     this.InjectionHeuristics = injectionHeuristics.ToList();
 }
Example #22
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="UIElementSelfBindingResolver" /> class.
 /// </summary>
 /// <param name="planner">The <see cref="IPlanner" /> component.</param>
 /// <param name="constructorScorer">The <see cref="IConstructorScorer" /> component.</param>
 public UIElementSelfBindingResolver(IPlanner planner, IConstructorScorer constructorScorer)
 {
     this.planner           = planner;
     this.constructorScorer = constructorScorer;
 }
 public ExplicitSelector(
     IConstructorScorer constructorScorer,
     IEnumerable <IInjectionHeuristic> injectionHeuristics)
     : base(constructorScorer, injectionHeuristics)
 {
 }