本文整理匯總了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);
}