當前位置: 首頁>>代碼示例>>C#>>正文


C# StandardKernel.Inject方法代碼示例

本文整理匯總了C#中Ninject.StandardKernel.Inject方法的典型用法代碼示例。如果您正苦於以下問題:C# StandardKernel.Inject方法的具體用法?C# StandardKernel.Inject怎麽用?C# StandardKernel.Inject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Ninject.StandardKernel的用法示例。


在下文中一共展示了StandardKernel.Inject方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CustomIdentity

 public CustomIdentity(FormsAuthenticationTicket ticket)
 {
     _ticket = ticket;
     var kernel = new StandardKernel();
     AccountRepository = new AccountRepository();
     kernel.Inject(AccountRepository);
 }
開發者ID:nategreenwood,項目名稱:SnippetCache,代碼行數:7,代碼來源:CustomIdentity.cs

示例2: SetUp

 public virtual void SetUp()
 {
     NinjectSettings settings = new NinjectSettings()
                                    {
                                        InjectNonPublic = true
                                    };
     IKernel kernel = new StandardKernel(settings, new CoreBindingModule(), new DataAccessBindingModule());
     kernel.Inject(this);
 }
開發者ID:jchadwick,項目名稱:developer-achievements,代碼行數:9,代碼來源:IntegrationTestFixture.cs

示例3: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            DependencyResolver.SetResolver(new NinjectDependencyResolver());

            var _kernel = new StandardKernel(new CoreInjectionModule());
            _kernel.Inject(Membership.Provider);
        }
開發者ID:xi33,項目名稱:ShaBoo,代碼行數:11,代碼來源:Global.asax.cs

示例4: CanResolveDependenciesOnExistingObject

        public void CanResolveDependenciesOnExistingObject()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IWeapon>().To<Lightsaber>();

            var darth = new SithLord();

            darth.Weapon.ShouldBeNull();

            kernel.Inject(darth);

            darth.Weapon.ShouldBeInstanceOf<Lightsaber>();
        }
開發者ID:DavidBasarab,項目名稱:Ninject-Examples,代碼行數:13,代碼來源:Chapter_05_Injection.cs

示例5: CanResolveDependenciesOnExistingObject

        public void CanResolveDependenciesOnExistingObject()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IWeapon>().To<Lightsaber>();

            var darth = new SithLord();

            Assert.That(darth.Weapon, Is.Null);

            kernel.Inject(darth);

            Assert.That(darth.Weapon, Is.InstanceOf<Lightsaber>());
        }
開發者ID:abalkany,項目名稱:Ninject-Examples,代碼行數:13,代碼來源:Chapter_05_Injection.cs

示例6: Deve_resolver_dependencias_manualmente

        public void Deve_resolver_dependencias_manualmente()
        {
            IKernel kernel = new StandardKernel(new Modulo());

            // A instância normal não tem as dependências resolvidas;
            var servico = new Servico();

            Assert.IsNull(servico.Fornecedor);

            // O método Inject resolve as dependências da instância usando como marcador o atributo [Inject];
            kernel.Inject(servico);

            Assert.IsNotNull(servico.Fornecedor);
            Assert.IsInstanceOfType(servico.Fornecedor, typeof(Fornecedor));
        }
開發者ID:devbychoice,項目名稱:NinjectInjecaoDependenciaSimples,代碼行數:15,代碼來源:DITestes.cs

示例7: BuildUp

        static void BuildUp()
        {
            Console.Write("Straight:\t");
            watch.Start();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                c.t = new TestClass1();
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("pooDI:\t\t");
            watch.Start();
            var pooDI = new DI.Container();
            pooDI.RegisterType<ITestClass1, TestClass1>(false);
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                pooDI.BuildUp<TestClass5>(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("Unity:\t\t");
            watch.Start();
            var unity = new UnityContainer();
            unity.RegisterType<ITestClass1, TestClass1>();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                unity.BuildUp<TestClass5>(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("Ninject:\t");
            watch.Start();
            var kernel = new StandardKernel();
            kernel.Bind<ITestClass1>().To<TestClass1>();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                kernel.Inject(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.Write("Autofac:\t");
            watch.Start();
            var builder = new ContainerBuilder();
            builder.RegisterType<TestClass1>().As<ITestClass1>();
            var container = builder.Build();
            for(int i = 0; i < n; ++i) {
                var c = new TestClass5();
                container.InjectProperties<TestClass5>(c);
            }
            watch.Stop();
            Console.WriteLine(watch.Elapsed);
            watch.Reset();

            Console.WriteLine("Castle Windsor:\tNot supported");
        }
開發者ID:KenjiTakahashi,項目名稱:pooDI,代碼行數:63,代碼來源:Program.cs

示例8: Initialize

 public void Initialize()
 {
     IKernel kernel = new StandardKernel(this.GetInstanceDIControllersModule());
     kernel.Settings.ActivationCacheDisabled = false;
     kernel.Inject(this);
 }
開發者ID:dramosti,項目名稱:SPED_1.0,代碼行數:6,代碼來源:BaseController.cs

示例9: InitialiseAdapter

        internal void InitialiseAdapter()
        {
            _logger.Info("Requesting Adapter Start");

            if (PlatformConnector == null)
            {
                _logger.Fatal("Plugin could not be found. Ensure that plugin is copied in folder and restart the service");
                return;
            }

            List<INinjectModule> modules = new List<INinjectModule> { new BootStrapper() };

            if (PluginBootstrapper != null)
            {
                _logger.InfoFormat("Plugin Bootstrapper found of type={0}", PluginBootstrapper.GetType().Name);
                modules.AddRange(PluginBootstrapper.BootstrapModules);
            }

            StandardKernel iocContainer = new StandardKernel(modules.ToArray());


            var settings = iocContainer.Get<ISettings>();
            var service = iocContainer.Get<IServiceFacade>();
            var streamListenerManager = iocContainer.Get<IStreamListenerManager>();
            
            iocContainer.Settings.InjectNonPublic = true;
            
            //needed for Plugin properties since plugin is not instantiated by Ninject
            iocContainer.Inject(PlatformConnector);

            _adapter = new Adapter(settings, service, PlatformConnector, streamListenerManager);

            if (settings.UseSupervisor)
            {
                // SS.Integration.Diagnostics.RestService uses Owin.HttpListeners.
                // that assembly must be referenced in the startup project even if not
                // directly used, so do not remove it from the list of references
                _supervisor = iocContainer.Get<ISupervisor>();
                if (_supervisor == null)
                {
                    _logger.Error("Cannot instantiate Supervisor as not suitable module was found");
                }
                else
                {
                    _logger.Info("Initializing adapter's supervisor");
                    try
                    {
                        _supervisor.Initialise();
                    }
                    catch (Exception e)
                    {
                        _logger.Error("An error occured during the initialization of the adapter's supervisor. The supervisor will not be available", e);
                    }
                }
            }


            _adapter.Start();

            _logger.Info("Adapter has started");
        }
開發者ID:luxbet,項目名稱:SS.Integration.Adapter,代碼行數:61,代碼來源:AdapterService.cs


注:本文中的Ninject.StandardKernel.Inject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。