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


C# StandardKernel.Get方法代码示例

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


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

示例1: ManyPublishersOneSubscriber

        public void ManyPublishersOneSubscriber()
        {
            using ( var kernel = new StandardKernel() )
            {
                var pub1 = kernel.Get<PublisherMock>();
                var pub2 = kernel.Get<PublisherMock>();
                Assert.NotNull( pub1 );
                Assert.NotNull( pub2 );

                var subscriber = kernel.Get<SubscriberMock>();
                Assert.NotNull( subscriber );

                Assert.True( pub1.HasListeners );
                Assert.True( pub2.HasListeners );
                Assert.Null( subscriber.LastMessage );

                pub1.SendMessage( "Hello, world!" );
                Assert.Equal( subscriber.LastMessage, "Hello, world!" );

                subscriber.LastMessage = null;
                Assert.Null( subscriber.LastMessage );

                pub2.SendMessage( "Hello, world!" );
                Assert.Equal( subscriber.LastMessage, "Hello, world!" );
            }
        }
开发者ID:larsw,项目名称:ninject.extensions.weakeventmessagebroker,代码行数:26,代码来源:MessageBrokerFixture.cs

示例2: SetUp

        public void SetUp()
        {
            IKernel kernel = new StandardKernel(new NinjectSettings {LoadExtensions = false});
            kernel.Load(new LinFuModule());
            kernel.Load(new TransactionalAnnotationTestModule());

            _targetService = kernel.Get<ITargetService>();
            _interceptor = (TestTransactionInterceptor) kernel.Get<ITransactionInterceptor>();
        }
开发者ID:cessationoftime,项目名称:ninject.extensions.spring.tx,代码行数:9,代码来源:TransactionalAnnotationTest.cs

示例3: CanResolveDetailedMatchAtEndOfInterface

 public void CanResolveDetailedMatchAtEndOfInterface()
 {
     var regexBindingGenerator = new RegexBindingGenerator("(IDefault)(?<name>.+)");
     using (IKernel kernel = new StandardKernel())
     {
         regexBindingGenerator.Process(typeof(DefaultView), StandardScopeCallbacks.Transient, kernel);
         kernel.GetBindings(typeof(IDefaultView)).Count().ShouldBe(1);
         kernel.Get<IDefaultView>().ShouldBeInstanceOf<DefaultView>();
         kernel.GetBindings(typeof(IDefaultConvention)).Count().ShouldBe(1);
         kernel.Get<IDefaultConvention>().ShouldBeInstanceOf<DefaultView>();
     }
 }
开发者ID:JohnMcCaffery,项目名称:ninject.extensions.conventions,代码行数:12,代码来源:RegexBindingGeneratorTests.cs

示例4: CanResolveDetailedMatchAtEndOfInterface

 public void CanResolveDetailedMatchAtEndOfInterface()
 {
     var regexBindingGenerator = new RegexBindingGenerator( "(IDefault)(?<name>.+)" );
     using ( IKernel kernel = new StandardKernel() )
     {
         regexBindingGenerator.Process( typeof (DefaultView), kernel );
         Assert.Equal( kernel.GetBindings( typeof (IDefaultView) ).Count(), 1 );
         Assert.IsType( typeof (DefaultView), kernel.Get<IDefaultView>() );
         Assert.Equal( kernel.GetBindings( typeof (IDefaultConvention) ).Count(), 1 );
         Assert.IsType( typeof (DefaultView), kernel.Get<IDefaultConvention>() );
     }
 }
开发者ID:andy78smith,项目名称:ninject.extensions.conventions,代码行数:12,代码来源:RegexBindingGeneratorTests.cs

示例5: ConstantsCanBePassedToToConstructor

        public void ConstantsCanBePassedToToConstructor()
        {
            using (IKernel kernel = new StandardKernel())
            {
                var ninja = new Ninja(new Sword());
                kernel.Bind<Barracks>().ToConstructor(_ => new Barracks(ninja));

                var barracks1 = kernel.Get<Barracks>();
                var barracks2 = kernel.Get<Barracks>();

                barracks1.Warrior.Should().BeSameAs(barracks2.Warrior);
            }
        }
开发者ID:Rolias,项目名称:ninject,代码行数:13,代码来源:ConstructorSelectionTests.cs

示例6: OpenGenericsAreFound

 public void OpenGenericsAreFound()
 {
     IKernel kernel = new StandardKernel();
     kernel.Scan(
         x =>
         {
             x.CallingAssembly();
             x.Using( new GenericBindingGenerator( typeof (IGenericView<>) ) );
         } );
     object target = kernel.Get<IGenericView<IDefaultConvention>>();
     Assert.IsAssignableFrom<DefaultConventionView>( target );
     target = kernel.Get<IGenericView<string>>();
     Assert.IsAssignableFrom<StringView>( target );
 }
开发者ID:andy78smith,项目名称:ninject.extensions.conventions,代码行数:14,代码来源:GenericBindingGeneratorTests.cs

示例7: Main

        public static void Main(string[] args)
        {
            using (var kernel = new StandardKernel(new ProgramModule()))
            {
                var interceptor = kernel.Get<ProfileInterceptor>();
                var worker = kernel.Get<IWorker>();

                worker.DoSomeWork();

                foreach (var snapshot in interceptor.Profiler.Snapshots)
                {
                    Console.WriteLine(snapshot.Time);
                }
            }
        }
开发者ID:VCipher,项目名称:Ninject.Extensions.Diagnostic,代码行数:15,代码来源:Program.cs

示例8: IsNotOverlappingWhenNoBoundingBoxes

 public void IsNotOverlappingWhenNoBoundingBoxes()
 {
     var kernel = new StandardKernel();
     kernel.Load<ProtogameCoreModule>();
     var boundingBoxUtilities = kernel.Get<IBoundingBoxUtilities>();
     _assert.False(boundingBoxUtilities.Overlaps());
 }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:7,代码来源:BoundingBoxTests.cs

示例9: InstanceIsDeactivatedWhenItLeavesScope

        public void InstanceIsDeactivatedWhenItLeavesScope()
        {
            Barracks barracks;
            using ( var kernel = new StandardKernel() )
            {
                kernel.Bind<Barracks>()
                    .ToSelf()
                    .InSingletonScope()
                    .OnActivation(instance =>
                                    {
                                        instance.Warrior = new FootSoldier();
                                        instance.Weapon = new Shuriken();
                                    })
                    .OnDeactivation(instance =>
                                    {
                                        instance.Warrior = null;
                                        instance.Weapon = null;
                                    });

                barracks = kernel.Get<Barracks>();
                barracks.Warrior.ShouldNotBeNull();
                barracks.Warrior.ShouldBeInstanceOf<FootSoldier>();
                barracks.Weapon.ShouldNotBeNull();
                barracks.Weapon.ShouldBeInstanceOf<Shuriken>();
            }
            barracks.Warrior.ShouldBeNull();
            barracks.Weapon.ShouldBeNull();
        }
开发者ID:Haacked,项目名称:ninject,代码行数:28,代码来源:ActivationStrategyTests.cs

示例10: ReplaceMapper

 public void ReplaceMapper() {
     var c = new StandardKernel();
     var mapper = new global::SolrNet.Tests.Mocks.MReadOnlyMappingManager();
     c.Load(new SolrNetModule("http://localhost:8983/solr") {Mapper = mapper});
     var m = c.Get<IReadOnlyMappingManager>();
     Assert.AreSame(mapper, m);
 }
开发者ID:FilipVV,项目名称:SolrNet,代码行数:7,代码来源:NinjectFixture.cs

示例11: TransientBindingsWork

        public void TransientBindingsWork()
        {
            var kernel = new StandardKernel();

            kernel.Get(
                typeof (IInput),
                null,
                null,
                null,
                null,
                null,
                new Dictionary<Type, List<IMapping>>
                {
                    {
                        typeof (IInput), new List<IMapping>
                        {
                            new DefaultMapping(
                                typeof(DefaultInput),
                                null,
                                false,
                                null,
                                null,
                                false,
                                false,
                                null)
                        }
                    }
                });
        }
开发者ID:hach-que,项目名称:Protoinject,代码行数:29,代码来源:TransientBindingsTests.cs

示例12: BindToSelectionReturnsSameInstanceForSameScope

        public void BindToSelectionReturnsSameInstanceForSameScope()
        {
            using (IKernel kernel = new StandardKernel())
            {
                kernel.Bind(
                    x => x.FromThisAssembly()
                          .Select(t => t == typeof(Foo))
                          .BindSelection((ts, ti) => ti)
                          .Configure(c => c.InSingletonScope()));

                var instance1 = kernel.Get<IFoo>();
                var instance2 = kernel.Get<IFoo<int>>();

                instance1.Should().BeSameAs(instance2);
            }
        }
开发者ID:EstevaoLuis,项目名称:ninject.extensions.conventions,代码行数:16,代码来源:InterfaceSegregationTests.cs

示例13: IsNotOverlappingWhenOneBoundingBox

 public void IsNotOverlappingWhenOneBoundingBox()
 {
     var kernel = new StandardKernel();
     kernel.Load<ProtogameCoreModule>();
     var boundingBoxUtilities = kernel.Get<IBoundingBoxUtilities>();
     _assert.False(boundingBoxUtilities.Overlaps(this.CreateBoundingBox(200, 200, 16, 16)));
 }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:7,代码来源:BoundingBoxTests.cs

示例14: AsyncActionTest

        public void AsyncActionTest()
        {
            using (var kernel = new StandardKernel())
            {
                // bindings
                kernel.Bind<ITestItem>().To<TestItem>();

                // initialize
                var item = kernel.Get<ITestItem>();
                var inteceptor = kernel.Get<ProfileInterceptor>();

                // asserting
                item.AsyncAction().Wait();
                Assert.AreEqual(1, inteceptor.Profiler.Snapshots.Count());
            }
        }
开发者ID:VCipher,项目名称:Ninject.Extensions.Diagnostic,代码行数:16,代码来源:ProfilerInterceptorTests.cs

示例15: IsNotOverlappingWhenSameBoundingBoxAndNoOtherBoxes

 public void IsNotOverlappingWhenSameBoundingBoxAndNoOtherBoxes()
 {
     var kernel = new StandardKernel();
     kernel.Load<ProtogameCoreModule>();
     var boundingBoxUtilities = kernel.Get<IBoundingBoxUtilities>();
     var entity = this.CreateBoundingBox(200, 200, 16, 16);
     _assert.False(boundingBoxUtilities.Overlaps(entity, entity));
 }
开发者ID:RedpointGames,项目名称:Protogame,代码行数:8,代码来源:BoundingBoxTests.cs


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