当前位置: 首页>>代码示例>>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;未经允许,请勿转载。