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