public void When_More_Constructors_Throws_Exception() { var serviceProvider = new BasicServiceProvider(); serviceProvider.Register <IChildThreeWithTwoConstructors, ChildThreeWithTwoConstructors>(); Assert.Throws <Exception>(() => serviceProvider.Resolve <IChildThreeWithTwoConstructors>()); }
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>()); }
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)); }
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); }