本文整理汇总了C#中Binder.GetBindingsFor方法的典型用法代码示例。如果您正苦于以下问题:C# Binder.GetBindingsFor方法的具体用法?C# Binder.GetBindingsFor怎么用?C# Binder.GetBindingsFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Binder
的用法示例。
在下文中一共展示了Binder.GetBindingsFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBindingToMultipleSingletonByInstance
public void TestBindingToMultipleSingletonByInstance()
{
var binder = new Binder();
binder.Bind<MockIClassWithAttributes>().To(new MockIClassWithAttributes());
binder.Bind<IMockInterface>().ToSingleton<MockIClassWithAttributes>();
var bindings1 = binder.GetBindingsFor<MockIClassWithAttributes>();
var bindings2 = binder.GetBindingsFor<IMockInterface>();
Assert.AreEqual(1, bindings1.Count);
Assert.AreEqual(1, bindings2.Count);
Assert.AreEqual(BindingInstance.Singleton, bindings1[0].instanceType);
Assert.AreEqual(BindingInstance.Singleton, bindings2[0].instanceType);
Assert.AreEqual(typeof(MockIClassWithAttributes), bindings1[0].type);
Assert.AreEqual(typeof(IMockInterface), bindings2[0].type);
Assert.AreEqual(bindings1[0].value, bindings1[0].value);
}
示例2: TestBindingToInstanceFromInterface
public void TestBindingToInstanceFromInterface()
{
var binder = new Binder();
var instance = new MockIClassWithAttributes();
binder.Bind<IMockInterface>().To<MockIClassWithAttributes>(instance);
var bindings = binder.GetBindingsFor<IMockInterface>();
Assert.AreEqual(1, bindings.Count);
Assert.AreEqual(BindingInstance.Singleton, bindings[0].instanceType);
Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
Assert.AreEqual(instance, bindings[0].value);
}
示例3: TestBindingToFactoryTypeFromInterface
public void TestBindingToFactoryTypeFromInterface()
{
var binder = new Binder();
var type = typeof(MockFactory);
binder.Bind<IMockInterface>().ToFactory(type);
var bindings = binder.GetBindingsFor<IMockInterface>();
Assert.AreEqual(1, bindings.Count);
Assert.AreEqual(BindingInstance.Factory, bindings[0].instanceType);
Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
Assert.AreEqual(type, bindings[0].value);
}
示例4: TestGetBindingsForGenerics
public void TestGetBindingsForGenerics()
{
var binder = new Binder();
binder.Bind<MockClassToDepend>().ToSelf();
binder.Bind(typeof(IMockInterface)).To<MockIClassWithAttributes>();
binder.Bind<IMockInterface>().To<MockIClassWithAttributes>().As("test");
var bindings = binder.GetBindingsFor<IMockInterface>();
Assert.AreEqual(2, bindings.Count);
Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
Assert.IsNull(bindings[0].identifier);
Assert.AreEqual(typeof(IMockInterface), bindings[1].type);
Assert.AreEqual("test", bindings[1].identifier);
}
示例5: TestGetBindingsForIdentifier
public void TestGetBindingsForIdentifier()
{
var binder = new Binder();
binder.Bind<MockClassToDepend>().ToSelf();
binder.Bind(typeof(MockIClassWithAttributes)).ToSelf();
binder.Bind<IMockInterface>().To<MockIClass>();
binder.Bind<IMockInterface>().To<MockIClassWithAttributes>().As("Identifier");
binder.Bind<IMockInterface>().To<MockIClassWithoutAttributes>().As("Identifier");
var bindings = binder.GetBindingsFor("Identifier");
Assert.AreEqual(2, bindings.Count);
Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
Assert.AreEqual(typeof(MockIClassWithAttributes), bindings[0].value);
Assert.AreEqual("Identifier", bindings[0].identifier);
Assert.AreEqual(typeof(IMockInterface), bindings[1].type);
Assert.AreEqual(typeof(MockIClassWithoutAttributes), bindings[1].value);
Assert.AreEqual("Identifier", bindings[1].identifier);
}
示例6: TestBindingToTransientFromInterface
public void TestBindingToTransientFromInterface()
{
var binder = new Binder();
binder.Bind<IMockInterface>().To<MockIClassWithAttributes>();
var bindings = binder.GetBindingsFor<IMockInterface>();
Assert.AreEqual(1, bindings.Count);
Assert.AreEqual(BindingInstance.Transient, bindings[0].instanceType);
Assert.AreEqual(typeof(IMockInterface), bindings[0].type);
Assert.AreEqual(typeof(MockIClassWithAttributes), bindings[0].value);
}
示例7: TestBindingToSingleton
public void TestBindingToSingleton()
{
var binder = new Binder();
binder.Bind<MockIClassWithAttributes>().ToSingleton();
var bindings = binder.GetBindingsFor<MockIClassWithAttributes>();
Assert.AreEqual(1, bindings.Count);
Assert.AreEqual(BindingInstance.Singleton, bindings[0].instanceType);
Assert.AreEqual(typeof(MockIClassWithAttributes), bindings[0].type);
Assert.AreEqual(typeof(MockIClassWithAttributes), bindings[0].value);
}
示例8: TestBindingToNamespaceTransient
public void TestBindingToNamespaceTransient()
{
var binder = new Binder();
binder.Bind<IMockInterface>().ToNamespace("Adic.Tests");
var bindings = binder.GetBindingsFor<IMockInterface>();
Assert.AreEqual(3, bindings.Count);
Assert.AreEqual(BindingInstance.Transient, bindings[0].instanceType);
Assert.AreEqual(BindingInstance.Transient, bindings[1].instanceType);
Assert.AreEqual(BindingInstance.Transient, bindings[2].instanceType);
Assert.AreEqual(typeof(MockIClass), bindings[0].value);
Assert.AreEqual(typeof(MockIClassWithoutAttributes), bindings[1].value);
Assert.AreEqual(typeof(MockIClassWithAttributes), bindings[2].value);
}