Example #1
0
        public void CanCallNonGenericConstructorOnOpenGenericType()
        {
            Container.RegisterType(typeof(ClassWithOneGenericParameter <>),
                                   new InjectionConstructor("Fiddle", new InjectionParameter <object>("someValue")));

            ClassWithOneGenericParameter <Service> result = Container.Resolve <ClassWithOneGenericParameter <Service> >();

            Assert.IsNull(result.InjectedValue);
        }
        public void CanCallConstructorTakingGenericParameterWithResolvableOptional()
        {
            Container.RegisterType(typeof(ClassWithOneGenericParameter <>),
                                   new InjectionConstructor(new OptionalGenericParameter("T")));

            Account a = new Account();

            Container.RegisterInstance <Account>(a);

            ClassWithOneGenericParameter <Account> result = Container.Resolve <ClassWithOneGenericParameter <Account> >();

            Assert.AreSame(a, result.InjectedValue);
        }
        public void CanConfiguredNamedResolutionOfOptionalGenericParameter()
        {
            Container.RegisterType(typeof(ClassWithOneGenericParameter <>),
                                   new InjectionConstructor(new OptionalGenericParameter("T", "named")));

            Account a = new Account();

            Container.RegisterInstance <Account>(a);
            Account named = new Account();

            Container.RegisterInstance <Account>("named", named);

            ClassWithOneGenericParameter <Account> result = Container.Resolve <ClassWithOneGenericParameter <Account> >();

            Assert.AreSame(named, result.InjectedValue);
        }