當前位置: 首頁>>代碼示例>>C#>>正文


C# Binder.GetBindingsFor方法代碼示例

本文整理匯總了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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:18,代碼來源:BindingPositiveTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:13,代碼來源:BindingPositiveTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:13,代碼來源:BindingPositiveTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:16,代碼來源:BinderTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:20,代碼來源:BinderTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:12,代碼來源:BindingPositiveTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:12,代碼來源:BindingPositiveTests.cs

示例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);
        }
開發者ID:NotYours180,項目名稱:adic,代碼行數:15,代碼來源:BindingPositiveTests.cs


注:本文中的Binder.GetBindingsFor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。