本文整理汇总了C#中Zenject.DiContainer.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# DiContainer.Bind方法的具体用法?C# DiContainer.Bind怎么用?C# DiContainer.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zenject.DiContainer
的用法示例。
在下文中一共展示了DiContainer.Bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBasicSuccess
public void TestBasicSuccess()
{
var container = new DiContainer();
container.Bind<IFoo>().ToSingle<Foo>();
container.Bind<Bar>().ToSingle();
Assert.That(container.ValidateResolve<IFoo>().IsEmpty());
}
示例2: InstallFoo
public void InstallFoo(DiContainer subContainer)
{
NumInstalls++;
subContainer.Bind<FooKernel>().AsSingle();
subContainer.Bind<IInitializable>().To<InitTest>().AsSingle();
subContainer.Bind<ITickable>().To<TickTest>().AsSingle();
subContainer.Bind<IDisposable>().To<DisposeTest>().AsSingle();
}
示例3: TestList
public void TestList()
{
var container = new DiContainer();
container.Bind<IFoo>().ToSingle<Foo>();
container.Bind<IFoo>().ToSingle<Foo2>();
container.Bind<Bar>().ToSingle();
container.Bind<Qux>().ToSingle();
Assert.That(container.ValidateResolve<Qux>().IsEmpty());
}
示例4: Test1
public void Test1()
{
NumInstalls = 0;
InitTest.WasRun = false;
TickTest.WasRun = false;
DisposeTest.WasRun = false;
var container = new DiContainer();
container.Bind(typeof(TickableManager), typeof(InitializableManager), typeof(DisposableManager))
.ToSelf().AsSingle().InheritInSubContainers();
// This is how you add ITickables / etc. within sub containers
container.BindAllInterfacesAndSelf<FooKernel>()
.To<FooKernel>().FromSubContainerResolve().ByMethod(InstallFoo).AsSingle();
var tickManager = container.Resolve<TickableManager>();
var initManager = container.Resolve<InitializableManager>();
var disposeManager = container.Resolve<DisposableManager>();
Assert.That(!InitTest.WasRun);
Assert.That(!TickTest.WasRun);
Assert.That(!DisposeTest.WasRun);
initManager.Initialize();
tickManager.Update();
disposeManager.Dispose();
Assert.That(InitTest.WasRun);
Assert.That(TickTest.WasRun);
Assert.That(DisposeTest.WasRun);
}
示例5: CreateContainer
public static DiContainer CreateContainer(bool allowNullBindings, GlobalCompositionRoot root)
{
Assert.That(allowNullBindings || root != null);
var container = new DiContainer(root == null ? null : root.transform);
container.AllowNullBindings = allowNullBindings;
container.Bind<GlobalCompositionRoot>().ToInstance(root);
container.Bind<CompositionRoot>().ToInstance(root);
container.Install<StandardInstaller>();
container.Install(GetGlobalInstallers());
return container;
}
示例6: TestValidateDynamicSuccess
public void TestValidateDynamicSuccess()
{
var container = new DiContainer();
container.Bind<Foo>().ToSingle();
Assert.That(container.ValidateObjectGraph<Foo>(typeof(Bar)).IsEmpty());
}
示例7: TestValidateDynamicFailure2
public void TestValidateDynamicFailure2()
{
var container = new DiContainer();
container.Bind<Foo>().ToSingle();
Assert.That(!container.ValidateObjectGraph<Foo>(typeof(Bar), typeof(string)).IsEmpty());
}
示例8: BindPriority
public static void BindPriority(
DiContainer container, Type tickableType, int priorityCount)
{
Assert.That(tickableType.DerivesFrom<IFixedTickable>(),
"Expected type '{0}' to derive from IFixedTickable", tickableType.Name());
container.Bind<ModestTree.Util.Tuple<Type, int>>("Fixed").ToInstance(
ModestTree.Util.Tuple.New(tickableType, priorityCount)).WhenInjectedInto<TickableManager>();
}
示例9: TestBindAllInterfacesSimple
public void TestBindAllInterfacesSimple()
{
var container = new DiContainer();
container.Bind(x => x.AllInterfaces()).To<Foo>();
Assert.That(container.Resolve<IFoo>() is Foo);
Assert.That(container.Resolve<IBar>() is Foo);
}
示例10: OnEnable
public virtual void OnEnable()
{
_container = new DiContainer(StaticContext.Container);
// Make sure we don't create any game objects since editor windows don't have a scene
_container.AssertOnNewGameObjects = true;
_container.Bind<TickableManager>().AsSingle();
_container.Bind<InitializableManager>().AsSingle();
_container.Bind<DisposableManager>().AsSingle();
_container.Bind<GuiRenderableManager>().AsSingle();
InstallBindings();
_container.Inject(this);
_initializableManager.Initialize();
}
示例11: TestBindAllInterfaces2
public void TestBindAllInterfaces2()
{
var container = new DiContainer();
container.Bind(x => x.AllInterfaces())
.To(x => x.AllNonAbstractClasses().InNamespace("Zenject.Tests.Convention.Two"));
Assert.IsEqual(container.ResolveAll<IFoo>().Count, 2);
Assert.IsEqual(container.ResolveAll<IBar>().Count, 2);
}
示例12: TestAny
public void TestAny()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
rootContainer.Bind<Test0>().AsSingle();
sub1.Bind<Test4>().AsSingle();
Assert.IsNotNull(sub1.Resolve<Test4>());
}
示例13: TestLocal1
public void TestLocal1()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
rootContainer.Bind<Test0>().AsSingle();
sub1.Bind<Test1>().AsSingle();
Assert.Throws(() => sub1.Resolve<Test1>());
}
示例14: TestLocal1
public void TestLocal1()
{
var rootContainer = new DiContainer();
var sub1 = rootContainer.CreateSubContainer();
rootContainer.Bind<Test0>().ToSingle();
sub1.Bind<Test1>().ToSingle();
Assert.Throws<ZenjectResolveException>(() => sub1.Resolve<Test1>());
Assert.That(sub1.ValidateResolve<Test1>().Any());
}
示例15: Test1
public void Test1()
{
DiContainer parentContainer = new DiContainer();
parentContainer.Bind<Foo>().ToTransient();
// ToTransient should always use the DiContainer given by the inject context
var subContainer = parentContainer.CreateSubContainer();
subContainer.Bind<int>().ToInstance<int>(5);
var foo = subContainer.Resolve<Foo>();
Assert.AreEqual(foo.Value, 5);
}