Ejemplo n.º 1
0
        public void CanMakeBusinessProcessWithDefaultBindingGenerator()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
                {
                    scanner.From(typeof(BusinessProcess).Assembly);
                    scanner.BindWith<DefaultBindingGenerator>();
                });

            BusinessProcess bp = kernel.Get<BusinessProcess>();

            Assert.IsNotNull(bp);
        }
Ejemplo n.º 2
0
        public void CanMakeBusinessProcessWithServiceToInterfaceBinder()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
            });

            BusinessProcess bp = kernel.Get<BusinessProcess>();

            Assert.IsNotNull(bp);
        }
Ejemplo n.º 3
0
        public void CanGetAllValidators()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(IValidator).Assembly);
                scanner.WhereTypeInheritsFrom<IValidator>();
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
            });
            var validators = kernel.GetAll<IValidator>();

            Assert.IsNotNull(validators);
            Assert.AreEqual(3, validators.Count());
        }
Ejemplo n.º 4
0
        public void CanFilterOutValidatorRegistrations()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(IValidator).Assembly);
                scanner.WhereTypeInheritsFrom<IValidator>();
                // excluding the FailValidator should leave 2 of them
                scanner.Where(t => t != typeof(FailValidator));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
            });
            var validators = kernel.GetAll<IValidator>();

            Assert.IsNotNull(validators);
            Assert.AreEqual(2, validators.Count());
        }
Ejemplo n.º 5
0
        public void CanMakeSingletonInstance()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InSingletonScope();
            });

            BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
            BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();

            Assert.AreSame(businessProcess1, businessProcess2);
        }
Ejemplo n.º 6
0
        public void CanMakeTransientInstanceWithSingletonDependenciesTwoScans()
        {
            IKernel kernel = new StandardKernel();

            // scan for types that are registered as singletons
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.Where(t => t != typeof(BusinessProcess));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InSingletonScope();
            });

            // scan for types that are registered as transient
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                scanner.Where(t => t == typeof(BusinessProcess));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InTransientScope();
            });

            BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
            BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();

            Assert.AreNotSame(businessProcess1, businessProcess2);
            Assert.AreSame(businessProcess1.CustomerService, businessProcess2.CustomerService);
            Assert.AreSame(businessProcess1.OrderService, businessProcess2.OrderService);
        }
Ejemplo n.º 7
0
        public void CanMakeTransientInstanceWithSingletonDependencies()
        {
            IKernel kernel = new StandardKernel();
            kernel.Scan(scanner =>
            {
                scanner.From(typeof(BusinessProcess).Assembly);
                // exclude the type 'BusinessProcess' from scanning and singleton
                // NInject will auto-resolve it as transient
                // I don't know how the reverse would be accomplished
                scanner.Where(t => t != typeof(BusinessProcess));
                scanner.BindWith<NinjectServiceToInterfaceBinder>();
                scanner.InSingletonScope();
            });
            BusinessProcess businessProcess1 = kernel.Get<BusinessProcess>();
            BusinessProcess businessProcess2 = kernel.Get<BusinessProcess>();

            Assert.AreNotSame(businessProcess1, businessProcess2);
            Assert.AreSame(businessProcess1.CustomerService, businessProcess2.CustomerService);
            Assert.AreSame(businessProcess1.OrderService, businessProcess2.OrderService);
        }
        private IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            kernel.Scan(x => x.WhereTypeIsInNamespace("FabrikamWidgets.Core.Services"));

            return kernel;
        }