当前位置: 首页>>代码示例>>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;未经允许,请勿转载。