當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。