当前位置: 首页>>代码示例>>C#>>正文


C# StandardKernel.Scan方法代码示例

本文整理汇总了C#中Ninject.StandardKernel.Scan方法的典型用法代码示例。如果您正苦于以下问题:C# StandardKernel.Scan方法的具体用法?C# StandardKernel.Scan怎么用?C# StandardKernel.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ninject.StandardKernel的用法示例。


在下文中一共展示了StandardKernel.Scan方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanMakeBusinessProcessWithDefaultBindingGenerator

        public void CanMakeBusinessProcessWithDefaultBindingGenerator()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
                {
                    scanner.From(typeof(BusinessProcess).Assembly);
                    scanner.BindWith<DefaultBindingGenerator>();
                });

            BusinessProcess bp = kernel.Get<BusinessProcess>();

            Assert.IsNotNull(bp);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:13,代码来源:NinjectTest.cs

示例2: CanMakeBusinessProcessWithServiceToInterfaceBinder

        public void CanMakeBusinessProcessWithServiceToInterfaceBinder()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
            });

            BusinessProcess bp = kernel.Get<BusinessProcess>();

            Assert.IsNotNull(bp);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:13,代码来源:NinjectTest.cs

示例3: CanGetAllValidators

        public void CanGetAllValidators()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(IValidator).Assembly);
                scanner.WhereTypeInheritsFrom<IValidator>();
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
            });
            var validators = kernel.GetAll<IValidator>();

            Assert.IsNotNull(validators);
            Assert.AreEqual(3, validators.Count());
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:14,代码来源:NinjectTest.cs

示例4: CanFilterOutValidatorRegistrations

        public void CanFilterOutValidatorRegistrations()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(IValidator).Assembly);
                scanner.WhereTypeInheritsFrom<IValidator>();
                // excluding the FailValidator should leave 2 of them
                scanner.Where(t => t != typeof(FailValidator));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
            });
            var validators = kernel.GetAll<IValidator>();

            Assert.IsNotNull(validators);
            Assert.AreEqual(2, validators.Count());
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:16,代码来源:NinjectTest.cs

示例5: CanMakeSingletonInstance

        public void CanMakeSingletonInstance()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InSingletonScope();
            });

            BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
            BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();

            Assert.AreSame(businessProcess1, businessProcess2);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:15,代码来源:NinjectTest.cs

示例6: CanMakeTransientInstanceWithSingletonDependenciesTwoScans

        public void CanMakeTransientInstanceWithSingletonDependenciesTwoScans()
        {
            IKernel kernel = new StandardKernel();

            // scan for types that are registered as singletons
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.Where(t => t != typeof(BusinessProcess));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InSingletonScope();
            });

            // scan for types that are registered as transient
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.Where(t => t == typeof(BusinessProcess));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InTransientScope();
            });

            BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
            BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();

            Assert.AreNotSame(businessProcess1, businessProcess2);
            Assert.AreSame(businessProcess1.CustomerService, businessProcess2.CustomerService);
            Assert.AreSame(businessProcess1.OrderService, businessProcess2.OrderService);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:29,代码来源:NinjectTest.cs

示例7: CanMakeTransientInstanceWithSingletonDependencies

        public void CanMakeTransientInstanceWithSingletonDependencies()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                // exclude the type 'BusinessProcess' from scanning and singleton
                // NInject will auto-resolve it as transient
                // I don't know how the reverse would be accomplished
                scanner.Where(t => t != typeof(BusinessProcess));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InSingletonScope();
            });
            BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
            BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();

            Assert.AreNotSame(businessProcess1, businessProcess2);
            Assert.AreSame(businessProcess1.CustomerService, businessProcess2.CustomerService);
            Assert.AreSame(businessProcess1.OrderService, businessProcess2.OrderService);
        }
开发者ID:AnthonySteele,项目名称:IoCComparison,代码行数:20,代码来源:NinjectTest.cs

示例8: CreateKernel

        private IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            kernel.Scan(x => x.WhereTypeIsInNamespace("FabrikamWidgets.Core.Services"));

            return kernel;
        }
开发者ID:101v,项目名称:HTML5-Line-of-Business-Starter-Kit,代码行数:8,代码来源:Global.asax.cs


注:本文中的Ninject.StandardKernel.Scan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。