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


C# StandardKernel.Bind方法代码示例

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


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

示例1: Configure

        /// <summary>
        /// Configures the DI container
        /// </summary>
        /// <returns>configured kernel</returns>
        static IKernel Configure()
        {
            var kernel = new StandardKernel();

			//TODO: Move this to a module
			kernel.Bind<IClock> ().To<LinuxSystemClock> ().InSingletonScope ();

            //infrastructure modules
			kernel.Load(new List<NinjectModule>()
            {
				new LoggingModule(new List<string>(){"Log.config"})
            });

			var logger = kernel.Get<ILogger> ();

			logger.Info ("Loading Plugins...");
			//plugins
			kernel.Load (new string[] { "*.Plugin.dll" });

			logger.Info ("Loading Core...");
			//core services/controllers
            kernel.Bind<IRaceController>().To<RaceController>()
                .InSingletonScope()
                .WithConstructorArgument("autoRoundMarkDistanceMeters", AppConfig.AutoRoundMarkDistanceMeters);
			kernel.Bind<Supervisor>().ToSelf()
                .InSingletonScope()
                .WithConstructorArgument("cycleTime", AppConfig.TargetCycleTime);
                
            return kernel;
        }
开发者ID:brookpatten,项目名称:MrGibbs,代码行数:34,代码来源:Program.cs

示例2: CreateKernel

        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            // Fetch application settings and instantiate a DoctrineShipsSettings object.
            DoctrineShipsSettings doctrineShipsSettings = new DoctrineShipsSettings(
                WebConfigurationManager.AppSettings["TaskKey"],
                WebConfigurationManager.AppSettings["SecondKey"],
                WebConfigurationManager.AppSettings["WebsiteDomain"],
                Conversion.StringToInt32(WebConfigurationManager.AppSettings["CorpApiId"]),
                WebConfigurationManager.AppSettings["CorpApiKey"],
                WebConfigurationManager.AppSettings["TwitterConsumerKey"],
                WebConfigurationManager.AppSettings["TwitterConsumerSecret"],
                WebConfigurationManager.AppSettings["TwitterAccessToken"],
                WebConfigurationManager.AppSettings["TwitterAccessTokenSecret"],
                WebConfigurationManager.AppSettings["Brand"]
            );

            var kernel = new StandardKernel();
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
            kernel.Bind<IDoctrineShipsServices>().To<DoctrineShipsServices>();
            kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
            kernel.Bind<IEveDataSource>().To<EveDataSourceCached>();
            kernel.Bind<IDbContext>().To<DoctrineShipsContext>();
            kernel.Bind<IDoctrineShipsRepository>().To<DoctrineShipsRepository>();
            kernel.Bind<IDoctrineShipsValidation>().To<DoctrineShipsValidation>();
            kernel.Bind<ISystemLogger>().To<SystemLogger>();
            kernel.Bind<ISystemLoggerStore>().To<DoctrineShipsRepository>();
            kernel.Bind<IDoctrineShipsSettings>().ToConstant(doctrineShipsSettings);

            RegisterServices(kernel);
            return kernel;
        }
开发者ID:jameswlong,项目名称:doctrineships,代码行数:36,代码来源:NinjectWebCommon.cs

示例3: Main

        static void Main(string[] args)
        {           
            IKernel kernel = new StandardKernel();
            kernel.Bind<IBookRepository>().To<XmlFileRepository>().WithConstructorArgument(@"../../books.xml");
            kernel.Bind<ILogger>().To<Logger>();            
            kernel.Bind<IXmlExporter>().To<LinqToXmlExporter>();
            kernel.Bind<IBookListService>().To<BookListService>();
            IBookList list = kernel.Get<BookList>();

            Console.WriteLine("list.Export ended correctly? : " + list.Export(@"../../exported.xml")); 

            IKernel kernelForFilteredList = new StandardKernel();
            kernelForFilteredList.Bind<IBookRepository>().To<BinaryFileRepository>().WithConstructorArgument(@"../../filteredbooks.txt");
            kernelForFilteredList.Bind<ILogger>().To<Logger>();
            kernelForFilteredList.Bind<IXmlExporter>().To<XmlWriterExporter>();
            kernelForFilteredList.Bind<IBookListService>().To<BookListService>();
            IBookList filteredList = kernelForFilteredList.Get<BookList>();

            Console.WriteLine("list.Filter ended correctly? : " + list.Filter((Book b) =>
            {
                if (b.Edition == 1)
                    return true;
                else 
                    return false;
            },
            filteredList));

            Console.WriteLine("filteredlist.Export ended correctly? : " + filteredList.Export(@"../../filteredexported.xml"));
            Console.WriteLine();

            // Uncomment this procedure to check, that all methods from Day7 works correctly
            //DoSomeStuffToEnsureThatAllWorks(list); 

            Console.ReadLine();
        }
开发者ID:Dmitry-Karnitsky,项目名称:Epam_ASP.NET_Courses,代码行数:35,代码来源:Program.cs

示例4: CreateKernel

 /// <summary>
 /// Creates the kernel that will manage your application.
 /// </summary>
 /// <returns>The created kernel.</returns>
 protected override IKernel CreateKernel()
 {
     var kernel = new StandardKernel();
     kernel.Bind<IHomeControllerModel>().To<HomeControllerModel>();
     kernel.Bind<ILog>().ToMethod(ctx => LogManager.GetLogger("xxx"));
     return kernel;
 }
开发者ID:nectide,项目名称:ninject.web.mvc,代码行数:11,代码来源:Global.asax.cs

示例5: Should_not_throw_exception_when_loading_multiple_inline_modules

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

            kernel.Bind<IService>().To<ServiceImpl>();
            kernel.Bind<IService2>().To<Service2Impl>();
        }
开发者ID:siimv,项目名称:Arc,代码行数:7,代码来源:NinjectTests.cs

示例6: Main

        static void Main(string[] args)
        {
            IKernel container = new StandardKernel();
            container.Bind<IBillingProcessor>().To<BillingProcessor>();
            container.Bind<ICustomer>().To<Customer>();
            container.Bind<INotifier>().To<Notifier>();
            container.Bind<ILogger>().To<Logger>();

            Console.WriteLine("NInject DI Container Example");
            Console.WriteLine();

            OrderInfo orderInfo = new OrderInfo()
            {
                CustomerName = "Miguel Castro",
                Email = "[email protected]",
                Product = "Laptop",
                Price = 1200,
                CreditCard = "1234567890"
            };

            Console.WriteLine("Production:");
            Console.WriteLine();

            Commerce commerce = container.Get<Commerce>();
            commerce.ProcessOrder(orderInfo);

            Console.WriteLine();
            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
开发者ID:tleviathan,项目名称:DeepDiveIntoDI,代码行数:30,代码来源:Program.cs

示例7: SetUp

		public void SetUp()
		{
			ReferenceManager = Substitute.For<IReferenceManagement>();
			AppraiserUserService = Substitute.For<IAppraiserUserService>();
			AppraisalCompanyService = Substitute.For<IAppraisalCompanyService>();
			ClientCompanyService = Substitute.For<IClientCompaniesListService>();
			ClientBranchesService = Substitute.For<IBranchesService>();
			ClientCompanyProfileService = Substitute.For<IClientCompanyProfileService>();
			Target = new CommonFunctionsController(AppraiserUserService, ClientBranchesService, ReferenceManager, AppraisalCompanyService, ClientCompanyService, ClientCompanyProfileService);

			IKernel kernel = new StandardKernel();
			var refRepository = Substitute.For<IReferenceRepository>();
			refRepository.GetRoles().ReturnsForAnyArgs(new List<Role>
			{
				new Role { DisplayName = "Appraiser", Id = 1 },
				new Role { DisplayName = "Appraisal Company Admin", Id = 2 },
				new Role { DisplayName = "DVS Super Admin", Id = 3 },
				new Role { DisplayName = "DVS Admin", Id = 4 },
				new Role { DisplayName = "Company Admin and Appraiser", Id = 5 }
			});
			refRepository.GetRole(RoleType.AppraisalCompanyAdmin).Returns(new Role { DisplayName = "Appraisal Company Admin", Id = 2 });
			refRepository.GetRole(RoleType.DvsAdmin).Returns(new Role { DisplayName = "DVS Admin", Id = 4 });

			kernel.Bind<IReferenceRepository>().ToConstant(refRepository);
			kernel.Bind<IReferenceManagement>().To<ReferenceManagement>().InSingletonScope();
			kernel.Bind<ICacheService>().To<FakeCacheService>();
			Singletones.NinjectKernel = kernel;
		}
开发者ID:evkap,项目名称:DVS,代码行数:28,代码来源:CommonFunctionsControllerTest.cs

示例8: Configure

        public static void Configure(StandardKernel kernel)
        {
            kernel.Bind(x => x.FromAssembliesMatching("Alejandria.*")
                                 .SelectAllClasses()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InTransientScope()));

            kernel.Bind(x => x.FromAssembliesMatching("Framework.*")
                                 .SelectAllClasses()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InTransientScope()));

            kernel.Bind(x => x.FromAssembliesMatching("Alejandria.*")
                                 .SelectAllInterfaces()
                                 .EndingWith("Factory")
                                 .BindToFactory()
                                 .Configure(c => c.InSingletonScope()));

            kernel.Bind(x => x.FromThisAssembly()
                                 .SelectAllInterfaces()
                                 .Including<IRunAfterLogin>()
                                 .BindAllInterfaces()
                                 .Configure(c => c.InSingletonScope()));

            kernel.Bind<IIocContainer>().To<NinjectIocContainer>().InSingletonScope();
            kernel.Rebind<IClock>().To<Clock>().InSingletonScope();
            //kernel.Bind<IMessageBoxDisplayService>().To<MessageBoxDisplayService>().InSingletonScope();
        }
开发者ID:pragmasolutions,项目名称:Alejandria,代码行数:28,代码来源:IoCConfig.cs

示例9: Injector

 static Injector()
 {
     Container = new StandardKernel();
     Container.Load(System.Reflection.Assembly.GetCallingAssembly());
     Container.Bind(x => x.FromThisAssembly().SelectAllClasses().BindDefaultInterface());
     Container.Bind(x => x.FromThisAssembly().SelectAllClasses().BindAllInterfaces());
 }
开发者ID:Tesserex,项目名称:C--MegaMan-Engine,代码行数:7,代码来源:Injector.cs

示例10: GetKernel

 private StandardKernel GetKernel()
 {
     var kernel = new StandardKernel();
     kernel.Bind<ISecurityProvider>().To<FakeSecurityProvider>();
     kernel.Bind<ISourceProvider>().To<FakeSourceProvider>();
     return kernel;
 }
开发者ID:AndrosovIgor,项目名称:Updater,代码行数:7,代码来源:Startup.cs

示例11: Main

        static void Main()
        {
            StandardKernel kernel = new StandardKernel();

            kernel.Bind<IValueCalculator>().To<LinqValueCalculator>();

            // Property

            //kernel.Bind<IDiscountHelper>().To<DefaultDiscountHelper>().WithPropertyValue("DiscountSize", 50m);

            // Constructor argument

            kernel.Bind<IDiscountHelper>().To<DefaultDiscountHelper>().WithConstructorArgument("discountRate", 50M);

            IValueCalculator valueCalc = kernel.Get<IValueCalculator>();

            ShoppingCart cart = new ShoppingCart(valueCalc);

            Console.WriteLine("Total is: {0}", cart.CalculateStockValue());

            // Self-binding

            // this:

            IValueCalculator calc2 = kernel.Get<IValueCalculator>();
            ShoppingCart cart2 = new ShoppingCart(calc2);

            // is equivalent to:

            ShoppingCart cart3 = kernel.Get<ShoppingCart>();

            //kernel.Bind<ShoppingCart>().ToSelf().WithParameter("<parameterName>", <paramvalue>);
        }
开发者ID:piotrosz,项目名称:MVCSamples,代码行数:33,代码来源:Program.cs

示例12: ViewModelLocator

        public ViewModelLocator()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IKeyboardService>().To<DefaultKeyboardService>();

            if (ViewModelBase.IsInDesignModeStatic)
            {
                kernel.Bind<IConfigurationService>().To<DesignConfigurationService>();
                kernel.Bind<INuiService>().To<MockNuiService>();
            }
            else
            {
                kernel.Bind<IConfigurationService>().To<AppConfigConfigurationService>();
                kernel.Bind<INuiService>().To<KinectNuiService>();
            }

            nuiService = kernel.Get<INuiService>();

            main = new MainViewModel(
                kernel.Get<IConfigurationService>(),
                nuiService,
                kernel.Get<IKeyboardService>());

            boundingBox = new BoundingBoxViewModel(
                nuiService);

            explorer = new ExplorerViewModel(
                nuiService, kernel.Get<IConfigurationService>());

            math = new MathViewModel();
        }
开发者ID:kindohm,项目名称:getstem-kinect-3d,代码行数:31,代码来源:ViewModelLocator.cs

示例13: ConstructorArguments_Void_ValueTypeParameters_InterceptorReplacingArgument

        public void ConstructorArguments_Void_ValueTypeParameters_InterceptorReplacingArgument()
        {
            const int DependencyNumber = 5;
            var fakeInterceptor = new Mock<IDynamicInterceptor>();
            fakeInterceptor
                .Setup(x => x.Intercept(It.IsAny<IInvocation>()))
                .Callback<IInvocation>(
                    invocation =>
                        {
                            if (invocation.Method.Name == "MultiplyInternalNumber")
                            {
                                invocation.Arguments[0] = 8;
                            }

                            invocation.Proceed(); 
                        });

            using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind<IDynamicInterceptorManager>().To<DynamicInterceptorManager>();
                kernel.Bind<IDependency>().To<Dependency>()
                    .WithConstructorArgument("number", DependencyNumber);
                kernel.Bind<IDynamicInterceptorCollection>()
                    .ToConstant(new FakeDynamicInterceptorCollection(fakeInterceptor.Object));

                var instance = kernel.Get<IntegrationWithConstructorArgument>();

                instance.InitializeInternalNumberFromDependency();

                // interceptor overrides 3 with 8
                instance.MultiplyInternalNumber(3);
                
                instance.AssertInternalNumberIs(40);
            }
        }
开发者ID:OmerRaviv,项目名称:StaticProxy.Fody,代码行数:35,代码来源:IntegrationTests.cs

示例14: ConstructorArguments_Void_ValueTypeParameters_NoInterceptor

        public void ConstructorArguments_Void_ValueTypeParameters_NoInterceptor()
        {
            const int DependencyNumber = 5;

            using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind<IDynamicInterceptorManager>().To<DynamicInterceptorManager>();
                kernel.Bind<IDynamicInterceptorCollection>().ToConstant(new FakeDynamicInterceptorCollection());
                kernel.Bind<IDependency>().To<Dependency>()
                    .WithConstructorArgument("number", DependencyNumber);

                var instance = kernel.Get<IntegrationWithConstructorArgument>();

                instance.AssertInternalNumberIs(0);

                instance.InitializeInternalNumberFromDependency();
                instance.AssertInternalNumberIs(5);

                instance.MultiplyInternalNumberByThree();
                instance.AssertInternalNumberIs(15);

                instance.MultiplyInternalNumber(4);
                instance.AssertInternalNumberIs(60);
            }
        }
开发者ID:OmerRaviv,项目名称:StaticProxy.Fody,代码行数:25,代码来源:IntegrationTests.cs

示例15: Main

        static void Main(string[] args)
        {
            try
            {

                // DI
                IKernel _kernal = new StandardKernel();
                _kernal.Bind<INLogger>().To<NLogger>().InSingletonScope();
                _kernal.Bind<IRepo>().To<Repo>().InSingletonScope();
                _kernal.Bind<IOutputHelper>().To<OutputHelper>().InSingletonScope();
                _logger = _kernal.Get<NLogger>();
                _repo = _kernal.Get<Repo>();
                _output = _kernal.Get<OutputHelper>();

                //ValidateRunLengths();
                var duplicates = ValidateIRIAVG();

                var export = new ExcelExport().AddSheet("Duplicates", duplicates.ToArray());
                export.ExportTo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), System.Configuration.ConfigurationManager.AppSettings["excel:exportFileName"].ToString()));
            }
            catch (Exception ex)
            {
                _output.Write(string.Format("Error: {0}", ex.Message), true);
            }
            Console.WriteLine("Done. Press any key to exist.");
            Console.ReadKey();
        }
开发者ID:srailsback,项目名称:RunLengthsProcessor,代码行数:27,代码来源:Program.cs


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