コード例 #1
0
        public static void Initialize()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterTypes(
                AllClasses.FromAssembliesInBasePath(),
                (c) => WithMappings.FromMatchingInterface(c));
        }
        public void GetsMatchingInterface()
        {
            WithMappings.FromMatchingInterface(typeof(TypeWithoutInterfaces)).AssertHasNoItems();
            WithMappings.FromMatchingInterface(typeof(DisposableType)).AssertHasNoItems();
            WithMappings.FromMatchingInterface(typeof(TestObject)).AssertContainsInAnyOrder(typeof(ITestObject));
            WithMappings.FromMatchingInterface(typeof(AnotherTestObject)).AssertHasNoItems();

            // Generics
            WithMappings.FromMatchingInterface(typeof(GenericTestObject <,>)).AssertContainsExactly(typeof(IGenericTestObject <,>));
            WithMappings.FromMatchingInterface(typeof(GenericTestObjectAlt <,>)).AssertHasNoItems();
            WithMappings.FromMatchingInterface(typeof(GenericTestObject <>)).AssertHasNoItems();
            WithMappings.FromMatchingInterface(typeof(GenericTestObject)).AssertHasNoItems();
        }
コード例 #3
0
        public void WhenFilteringToMatchingInterface()
        {
            IUnityContainer container = new UnityContainer();

            var mappings = WithMappings.FromMatchingInterface(typeof(TypeImplementing8));

            container.RegisterTypes(
                AllClasses.FromAssemblies(Assembly.Load(new AssemblyName(RegistrationByConventionAssembly1Name))),
                WithMappings.FromMatchingInterface,
                WithName.TypeName,
                WithLifetime.Transient,
                null,
                true);

            var resolved = container.Resolve <ITypeImplementing8>("TypeImplementing8");

            Assert.IsInstanceOfType(resolved, typeof(TypeImplementing8));
        }