示例#1
0
        public void CanRegisterSetOfFilteredTypes_AsServiceDescriptor()
        {
            var catalog = new TypeCatalog(new ServiceCollection(),
                                          typeof(ComponentOne),
                                          typeof(ComponentTwo));

            catalog.AsDescriptor(
                t => t.Name.StartsWith("Component", System.StringComparison.Ordinal),
                t => ServiceDescriptor.Transient(t, t));

            Assert.Equal(2, catalog.Services.Count);
            Assert.True(catalog.Services.All(s => s.Lifetime == ServiceLifetime.Transient));
            Assert.Contains(catalog.Services, s => s.ImplementationType == typeof(ComponentOne));
            Assert.Contains(catalog.Services, s => s.ImplementationType == typeof(ComponentTwo));
        }