예제 #1
0
        public void When_More_Constructors_Throws_Exception()
        {
            var serviceProvider = new BasicServiceProvider();

            serviceProvider.Register <IChildThreeWithTwoConstructors, ChildThreeWithTwoConstructors>();

            Assert.Throws <Exception>(() => serviceProvider.Resolve <IChildThreeWithTwoConstructors>());
        }
예제 #2
0
        public void When_Not_Registered_Resolution_Throws_Key_Not_Found_Exception()
        {
            var serviceProvider = new BasicServiceProvider();

            serviceProvider.Register <IRootType, RootType>();
            serviceProvider.Register <IChildOne, ChildOne>();

            Assert.Throws <KeyNotFoundException>(() => serviceProvider.Resolve <IRootType>());
        }
예제 #3
0
        public int Parse(string[] args)
        {
            var serviceProvider = new BasicServiceProvider();

            RegisterServices(serviceProvider);
            _configureServiceAction?.Invoke(serviceProvider);
            serviceProvider.Register(typeof(IServiceProvider), serviceProvider);
            return(serviceProvider.Resolve <ICommandCoreVerbRunner>().Run(args));
        }
예제 #4
0
        public void When_Registered_Resolve_Instantiates_Dependency_Tree()
        {
            var serviceProvider = new BasicServiceProvider();

            serviceProvider.Register <IRootType, RootType>();
            serviceProvider.Register <IChildOne, ChildOne>();
            serviceProvider.Register <IChildTwo, ChildTwo>();
            serviceProvider.Register <IGrandChildOne, GrandChildOne>();

            var instance = serviceProvider.Resolve <IRootType>();

            Assert.NotNull(instance);

            Assert.NotNull(instance.ChildOne);
            Assert.NotNull(instance.ChildTwo);

            Assert.NotNull(instance.ChildTwo.GrandChildOne);
        }