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


C# StandardKernel.Get方法代码示例

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


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

示例1: AwardScholarship

        /// <summary>
        /// Award scholarship
        /// </summary>
        public void AwardScholarship()
        {
            // Wrote the resolver myself
            var resolver = new Resolver();

            var rankBy1 = resolver.ChooseRanking("undergrad");
            var award1 = new Award(rankBy1);

            award1.AwardScholarship("100");

            var rankBy2 = resolver.ChooseRanking("grad");
            var award2 = new Award(rankBy2);
            award2.AwardScholarship("200");

            // using Ninject instead of the custom resolver I wrote.
            var kernelContainer = new StandardKernel();
            kernelContainer.Bind<IRanking>().To<RankByGPA>();
            var award3 = kernelContainer.Get<Award>();
            award3.AwardScholarship("101");

            kernelContainer.Rebind<IRanking>().To<RankByInnovation>();
            var award4 = kernelContainer.Get<Award>();
            award4.AwardScholarship("201");

            // using Unity instead of custom resolver.
            var unityContainer = new UnityContainer();
            unityContainer.RegisterType<IRanking, RankByGPA>();
            var award5 = unityContainer.Resolve<Award>();
            award5.AwardScholarship("102");

            unityContainer = new UnityContainer();
            unityContainer.RegisterType<IRanking, RankByInnovation>();
            var award6 = unityContainer.Resolve<Award>();
            award6.AwardScholarship("202");
        }
开发者ID:calmajos,项目名称:enterprise-web-app-136,代码行数:38,代码来源:AwardClient.cs

示例2: Main

        /// <summary>
        /// Main 程序启动入口.
        /// </summary>
        /// <param name="args">命令行 参数</param>
        public static void Main(string[] args)
        {
            using (StandardKernel kernal = new StandardKernel(new MyModule()))
            {
                // 取得 停车场实现.
                ICarPark carpark = kernal.Get<ICarPark>();

                // 取得 车牌扫描实现.
                ICarNumberScan carNumSacn = kernal.Get<ICarNumberScan>();

                // 取得 车牌号码.
                string carNum = carNumSacn.GetCarNumber();

                for (int i = 1; i < 5; i++)
                {
                    // 进入车库.
                    carpark.InCarPark(carNum);

                    Thread.Sleep(1000 + i);

                    // 离开车库.
                    carpark.OutCarPark(carNum);
                }

                Console.ReadLine();
            }
        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:31,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            DirEx direx;
            if (!ArgsBinder.TryParse(args, out direx))
            {
                throw new ArgsExeption(args);
            }

            IKernel kernal = new StandardKernel();
            kernal.Load(Assembly.GetExecutingAssembly());

            IFileAction<string> fileAction = kernal.Get<IFileAction<string>>();
            fileAction.Output = kernal.Get<IFileActionResult<string>>();

            direx.OnFile += Direx_OnFileAction;
            direx.OnDirectory += Direx_OnDirectory;
            direx.Action(fileAction);

            if (fileAction.Output is IDisposable)
                ((IDisposable)fileAction.Output).Dispose();

#if DEBUG
            Cmd.ReadKey();
#endif
        }
开发者ID:Interreto,项目名称:.net,代码行数:25,代码来源:Program.cs

示例4: Register

        public static StandardKernel Register( HttpConfiguration config )
        {
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind<IRepository>().ToConstant( new MongoRepository( ConfigurationManager.ConnectionStrings[ "Mongo" ].ConnectionString, "gemfire" ) );
            }
            catch ( Exception ex ) // probably a bad/missing connection string for the mongodb, just use an in-memory store to get running instead
            {
                kernel.Bind<IRepository>().ToConstant( new MemoryRepository() );
            }

            var repo = kernel.Get<IRepository>();

            kernel.Bind<IGameHandler>().ToConstant( new GameHandler( repo ) );
            kernel.Bind<ILoginHandler>().ToConstant( new LoginHandler() );
            kernel.Bind<IRegistrationHandler>().ToConstant( new RegistrationHandler() );
            kernel.Bind<IUserHandler>().ToConstant( new UserHandler( repo ) );
            kernel.Bind<IMappingHandler>().ToConstant( new AutoMapMappingHandler( kernel.Get<IUserHandler>() ) );
            kernel.Bind<IScenarioHandler>().ToConstant( new ScenarioHandler() );

            DependencyResolver.SetResolver( new NinjectMVCDependencyResolver( kernel ) );
            GlobalHost.DependencyResolver = new NinjectSignalRDependencyResolver( kernel );

            return kernel;
        }
开发者ID:noobouse,项目名称:gemfire,代码行数:27,代码来源:IocConfig.cs

示例5: 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

示例6: Main

        public static void Main()
        {
            // Simulate heavy load, collect frequently
            var task = new Task(() =>
            {
                while (true)
                {
                    Thread.Sleep(500);

                    Console.WriteLine("test");
                    GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                    GC.WaitForPendingFinalizers();
                }
            });

            task.Start();

            var settings = new NinjectSettings {CachePruningInterval = new TimeSpan(0, 0, 5)};
            IKernel kernel = new StandardKernel(settings, new NinjectBindingsModule());

            PrintLoadedModules(kernel);

            var processor = kernel.Get<IMainProcessor>();
            processor.ProcessOnce();
            processor.ProcessOnce(); // second time is successful just as much
            Thread.Sleep(5000);

            var processor2 = kernel.Get<IMainProcessor>();
            processor2.ProcessOnce(); // ScopeDisposedException
        }
开发者ID:b3rnhard,项目名称:NinjectNamedScopesStrangeness,代码行数:30,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            ArgParser.Parse(Config, args);

            Kernel = new StandardKernel();

            Kernel.Load(AppDomain.CurrentDomain.GetAssemblies());

            var repo = Kernel.Get<IRepository>();

            var serial = Kernel.Get<ISerializer>();

            var testResult = Kernel.Get<TestRunResult>();

            if (File.Exists("Config.cfg"))
                Config = serial.ReadFile<BehaviorConfiguration>("Config.cfg");

            repo.DataPath = Config.DataPath;

            testResult.StartTime = DateTime.Now;

            repo.GetAllStories(Config).ForEach(f => testResult.StoryResults.Add(f.Run(Kernel.Get<IRestClient>())));

            testResult.EndTime = DateTime.Now;

            (new TestRunReport(testResult.SetResult())).ToFile(Config.ResultFile);
        }
开发者ID:ihenehan,项目名称:Behavior,代码行数:27,代码来源:Behavior.cs

示例8: Main

        public static void Main()
        {
            try
            {
                var module = new TriangleModule();
                var kernel = new StandardKernel(module);
                //var context = ZmqContext.Create();
                //var receiver = new MessageReceiver(context);
                //receiver.Listen();
                //var bus = new MessageBus(new MessageSender(context), receiver, new MessageRegistrationList());

                var selectableObjectRepository = kernel.Get<SelectableObjectRepository>();

                //var renderer = kernel.Get<Renderer>();
                //var form = kernel.Get<Form1>();
                //form.GO();
                //renderer.StartRendering();

                var form = kernel.Get<GameFormWpf>();
                form.GO();

                kernel.Dispose();
            }
            catch (OperationCanceledException) { }
        }
开发者ID:anthony-martin,项目名称:Triangles-in-space,代码行数:25,代码来源:TrianglesInSpace.cs

示例9: Main

        static void Main(string[] args)
        {
            Parser.Parse(Config, args);

            Kernel = new StandardKernel();

            Kernel.Load(AppDomain.CurrentDomain.GetAssemblies());

            var repo = Kernel.Get<IRepository>();

            var serial = Kernel.Get<ISerializer>();

            var testResult = Kernel.Get<TestRunResult>();

            if (File.Exists("Config.cfg"))
                Config = serial.ReadFile<BehaviorConfiguration>("Config.cfg");

            repo.DataPath = Config.DataPath;

            var stories = repo.GetItemsWithTaggedChildren(repo.GetAll<Story>(), Config.IncludeTags, Config.ExcludeTags).OrderBy(s => s.Name).ToList();

            stories.ForEach(s => testResult.StoryResults.Add((s as Story).Run(Kernel.Get<ILauncherClient>())));

            testResult.SetResult();

            var testReport = new TestRunReport(testResult);

            testReport.ToFile("TestResults.html");
        }
开发者ID:ihenehan,项目名称:Behavior,代码行数:29,代码来源:Behavior.cs

示例10: ResolveAuto

 public void ResolveAuto()
 {
     var kernel = new StandardKernel();
     var simpleClass1 = kernel.Get<Simple>();
     var simpleClass2 = kernel.Get<Simple>();
     Assert.AreNotSame(simpleClass1, simpleClass2);
 }
开发者ID:JohanLarsson,项目名称:IoCBoxNoUi,代码行数:7,代码来源:Samples.cs

示例11: Main

        static void Main(string[] args)
        {
            var kernel = new StandardKernel();
            kernel.Bind<IDictionaryService>().To<DictionaryService>();
            kernel.Bind<IYammerMessageResponseDeserializer>().To<YammerMessageResponseDeserializer>();
            kernel.Bind<IYammerMessageDatabaseManager>().To<YammerMessageDatabaseManager>();
            kernel.Bind<IYammerMessagePoster>().To<YammerMessagePoster>();
            kernel.Bind<IYammerMessageFetcher>().To<YammerMessageFetcher>();
            kernel.Bind<IYammerMessageServiceManager>().To<YammerMessageServiceManager>();
            kernel.Bind<IYammerTaskRunner>().To<YammerTaskRunner>();
            kernel.Bind<IQuoteRetriever>().To<QuoteRetriever>();
            kernel.Bind<ILoopingTaskRunner>().To<LoopingTaskRunner>();
            kernel.Bind<IEnvironmentInfoProvider>().To<EnvironmentInfoProvider>();
            kernel.Bind<IFileDataProvider>().To<FileDataProvider>();
            kernel.Bind<ISleeper>().To<ThreadSleeper>();
            kernel.Bind<IYammerResponseFetcher>().To<YammerResponseFetcher>();
            kernel.Bind<IYammerCommandFetcher>().To<YammerCommandFetcher>();
            kernel.Bind<IRandomNumberGenerator>().To<RandomNumberGenerator>();
            kernel.Bind<IComplimentFetcher>().To<ComplimentFetcher>();
            kernel.Bind<IComplimentService>().To<ComplimentService>();
            kernel.Bind<IComplimentTextDeserializer>().To<ComplimentTextDeserializer>();
            kernel.Bind<IComplimentTextTransformer>().To<ComplimentTextTransformer>();
            kernel.Bind<IYammerService>().To<YammerService>();
            kernel.Bind<IOauthValueProvider>().To<OauthValueProvider>();

            kernel.Bind<IOauthSessionProvider>().To<OauthSessionProvider>().InSingletonScope();
            kernel.Bind<IYammerDatabase>().To<YammerDatabase>().InSingletonScope();

            var runner = kernel.Get<IYammerTaskRunner>();
            var looper = kernel.Get<ILoopingTaskRunner>();

            looper.AddTask(60000, runner.ExecuteReplies);
        }
开发者ID:cbadke,项目名称:yammerbot,代码行数:33,代码来源:Program.cs

示例12: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main()
        {
            var kernel = new StandardKernel(new ServiceModule(), new WindowsTimeServiceModule());           

#if SERVICE
            var ServicesToRun = new System.ServiceProcess.ServiceBase[]
                                {
                                    kernel.Get<WindowsTimeService>()
                                };
            System.ServiceProcess.ServiceBase.Run( ServicesToRun );
#else
            var service = kernel.Get<WindowsTimeService>();
            try
            {
                service.Start(new string[] { });

                do
                {
                } 
                while (Console.ReadLine() != "q");
            }
            finally
            {
                service.Stop();
            }
#endif
        }
开发者ID:cbertolasio,项目名称:ninject.extensions.wcf,代码行数:30,代码来源:Program.cs

示例13: Main

        static void Main(string[] args)
        {
            Logger.Current.BinaryFileTraceLevel=TraceLevel.Verbose;
            Logger.DefaultBinaryFile.Open();

            IKernel kernel = new StandardKernel(new AutoMapperModule(), new BusinessModule(), new NHibernateModule(), new WCFModule());

            var _serviceManager = kernel.Get<ServiceManager>();

            var _serviceThread = new Thread(_serviceManager.RunServiceManager);

            _serviceThread.Start();

            var _host = new ServiceHost(kernel.Get<ILocationService>(), new Uri("http://localhost:9090/Jimbe"));
            var smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;

            _host.Description.Behaviors.Add(smb);
            _host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
            _host.AddServiceEndpoint(typeof (ILocationService),
                                     new WSDualHttpBinding(), "");
            _host.Open();

            Console.WriteLine("Host opened");
            Console.ReadLine();
            _serviceManager.RequestStop();
        }
开发者ID:ecanzonieri,项目名称:JimbeSoftware,代码行数:28,代码来源:Program.cs

示例14: Main

        static void Main(string[] args)
        {
            //container is called kernal (because it represents the kernal / core of the application

              //var kernal = new StandardKernel();
              //kernal.Bind<ICreditCard>().To<MasterCard>();

              var kernal = new StandardKernel(new MyModule());
              //kernal.Rebind<ICreditCard>().To<MasterCard>();

              //dont have to register all the types.. ninject will automatically register concrete types so we can ask for any concrete type and ninject will know how to create it.. without us having to speciy it specificallly in the container.. makes it a little easier so we don't have to configure every single class that we are going to use.
              //(dont need to register shopper type because its automatic)
              //whenever we ask for an ICreditCard were going to get back a MasterCard.

              var shopper = kernal.Get<Shopper>();
              shopper.Charge();
              Console.WriteLine(shopper.ChargesForCurrentCard);

              kernal.Rebind<ICreditCard>().To<MasterCard>();

              var shopper2 = kernal.Get<Shopper>();
              shopper2.Charge();
              Console.WriteLine(shopper2.ChargesForCurrentCard);

              //Shopper shopper3 = new Shopper();
              //shopper3.Charge();
              //Console.WriteLine(shopper3.ChargesForCurrentCard);

              Console.Read();
        }
开发者ID:KHProjects,项目名称:KH-Parker-Fox,代码行数:30,代码来源:Program.cs

示例15: Main

        static void Main(string[] args)
        {
            Ninject.IKernel kernal = new StandardKernel(new Core());
            ////kernal.Bind<IMsgRepo>().To<MsgRepo>();
            _repo = kernal.Get<MsgRepo>();

            _svc = kernal.Get<MsgService>();

            var svcreplies = _svc.GetReplies();
            foreach (var x in svcreplies)
            {
                Console.WriteLine(x.Body);
            }

            Console.WriteLine("enter reply");
            var consoleReply = Console.ReadLine();

            var reply = new Reply()
            {
                Body = consoleReply,
                Created = DateTime.Now,
                TopicId = 1

            };

            _repo.InsertReply(reply);

            var replies = _repo.GetReplies();
            _repo.DeleteReply(replies.First().Id);

            foreach (var x in replies)
            {
                Console.WriteLine(x.Body);
            }

            Main(args);

            //var baseClass = new BaseClass();
            //var derivedOverride = new DerivedOverride();
            //var derivedNew = new DerivedNew();
            //var derivedOverWrite = new DerivedOverwrite();

            //baseClass.Name();
            //derivedOverride.Name();
            //derivedNew.Name();
            //derivedOverWrite.Name();

            //Console.ReadLine();
            //baseClass.Name();
            //derivedOverride.Name();
            //((BaseClass)derivedNew).Name();
            //((BaseClass)derivedOverWrite).Name();
            //Console.ReadLine();

            //var t1 = typeof(BaseClass);
            //Console.WriteLine(t1.Name);
            //Console.WriteLine(t1.Assembly);

            //Console.ReadLine();
        }
开发者ID:MacMcDell,项目名称:moqTests,代码行数:60,代码来源:Program.cs


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