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


C# IocContainer.GetRegistrations方法代碼示例

本文整理匯總了C#中System.IocContainer.GetRegistrations方法的典型用法代碼示例。如果您正苦於以下問題:C# IocContainer.GetRegistrations方法的具體用法?C# IocContainer.GetRegistrations怎麽用?C# IocContainer.GetRegistrations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IocContainer的用法示例。


在下文中一共展示了IocContainer.GetRegistrations方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: NonGenericGetRegistrationsIncludesAllButOnlyExpectedRegistrations

        public void NonGenericGetRegistrationsIncludesAllButOnlyExpectedRegistrations()
        {
            using (var iocContainer = new IocContainer())
            {
                var namelessFoo = iocContainer.Register(typeof(IFoo), c => new Foo1());
                var bobFoo = iocContainer.Register("Bob", typeof(IFoo), c => new Foo2());
                var billFoo = iocContainer.Register("Bill", typeof(IFoo), c => new Foo2());
                var janeBar = iocContainer.Register("Jane", typeof(IBar), c => new Bar1());

                var result = iocContainer.GetRegistrations(typeof(IFoo));

                Verify.That(result.ToList()).IsACollectionThat()
                           .IsAnInstanceOfType(typeof(List<IRegistration>))
                           .Count().IsEqualTo(3)
                           .AllItemsAreInstancesOfType(typeof(IRegistration))
                           .Contains(namelessFoo)
                           .Contains(bobFoo)
                           .Contains(billFoo)
                           .DoesNotContain(janeBar);
            }
        }
開發者ID:jlaanstra,項目名稱:Munq,代碼行數:21,代碼來源:ContainerInterfaceTests.cs

示例2: GetRegistrationsReturnsAnEmptyListIfNoRegistrationsOfTheRequesetedType

        public void GetRegistrationsReturnsAnEmptyListIfNoRegistrationsOfTheRequesetedType()
        {
            using (var iocContainer = new IocContainer())
            {
                iocContainer.Register<IFoo>(c => new Foo1());
                iocContainer.Register<IFoo>("Bob", c => new Foo2());
                iocContainer.Register<IFoo>("Bill", c => new Foo2());

                var result = iocContainer.GetRegistrations<IBar>();

                Verify.That(result.ToList()).IsACollectionThat()
                           .IsAnInstanceOfType(typeof(List<IRegistration>))
                           .Count().IsEqualTo(0);
            }
        }
開發者ID:jlaanstra,項目名稱:Munq,代碼行數:15,代碼來源:ContainerInterfaceTests.cs


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