本文整理汇总了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!" );
}
}
示例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>();
}
示例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>();
}
}
示例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>() );
}
}
示例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);
}
}
示例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 );
}
示例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);
}
}
}
示例8: IsNotOverlappingWhenNoBoundingBoxes
public void IsNotOverlappingWhenNoBoundingBoxes()
{
var kernel = new StandardKernel();
kernel.Load<ProtogameCoreModule>();
var boundingBoxUtilities = kernel.Get<IBoundingBoxUtilities>();
_assert.False(boundingBoxUtilities.Overlaps());
}
示例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();
}
示例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);
}
示例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)
}
}
});
}
示例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);
}
}
示例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)));
}
示例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());
}
}
示例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));
}