public void CanResolveClassWithOneDependencyByInterface()
        {
            var box = new Box();
            box.Register<FirstDependencyClass>();
            box.Register<ISomethingWithDependency, SomethingWithDependency>();

            var obj = box.Resolve<ISomethingWithDependency>();
            Assert.That(obj, Is.Not.Null);
            Assert.That(obj.FirstDependency, Is.Not.Null);
        }
        public void CanResolveClassWithOneDependency()
        {
            var box = new Box();
            box.Register<FirstDependencyClass>();
            box.Register<OneDependencyClass>();

            var obj = box.Resolve<OneDependencyClass>();
            Assert.That(obj, Is.Not.Null);
            Assert.That(obj.FirstDependency, Is.Not.Null);
        }
        public void CanResolveClassWithTwoDependencyLevels()
        {
            var box = new Box();
            box.Register<TopLevelClass>();
            box.Register<FirstLevelDependency>();
            box.Register<SecondLevelDependency>();

            var obj = box.Resolve<TopLevelClass>();
            Assert.That(obj, Is.Not.Null);
            Assert.That(obj.FirstLevelDependency, Is.Not.Null);
            Assert.That(obj.FirstLevelDependency.SecondLevelDependency, Is.Not.Null);
        }
        public void DifferentLifeStylesTestByInterface()
        {
            var box = new Box();
            box.Register<FirstDependencyClass>();
            box.Register<ISomethingWithDependency, SomethingWithDependency>(LifeStyle.NewPerResolve);
            box.Register<ISomething, Something>(LifeStyle.SingleForContainer);

            var obj11 = box.Resolve<ISomethingWithDependency>();
            var obj12 = box.Resolve<ISomethingWithDependency>();
            Assert.That(ReferenceEquals(obj11, obj12), Is.False);

            var obj21 = box.Resolve<ISomething>();
            var obj22 = box.Resolve<ISomething>();
            Assert.That(ReferenceEquals(obj21, obj22), Is.True);
        }
        public void DifferentLifeStylesTestByClass()
        {
            var box = new Box();
            box.Register<NoDependenciesClass>(LifeStyle.NewPerResolve);
            box.Register<FirstDependencyClass>(LifeStyle.SingleForContainer);
            box.Register<OneDependencyClass>(LifeStyle.SingleForContainer);

            var obj11 = box.Resolve<NoDependenciesClass>();
            var obj12 = box.Resolve<NoDependenciesClass>();
            Assert.That(ReferenceEquals(obj11, obj12), Is.False);

            var obj21 = box.Resolve<OneDependencyClass>();
            var obj22 = box.Resolve<OneDependencyClass>();
            Assert.That(ReferenceEquals(obj21, obj22), Is.True);
        }
        public void CanResolveByInterface()
        {
            var box = new Box();
            box.Register<ISomething, Something>();

            var resolvedObject = box.Resolve<ISomething>();
            Assert.That(resolvedObject, Is.Not.Null);
        }
        public void CanResolveByClass()
        {
            var box = new Box();
            box.Register<NoDependenciesClass>();

            var resolvedObj = box.Resolve<NoDependenciesClass>();
            Assert.That(resolvedObj, Is.Not.Null);
        }
        public void NewPerResolveLifeStyleTestByClass()
        {
            var box = new Box();
            box.Register<NoDependenciesClass>(LifeStyle.NewPerResolve);

            var obj1 = box.Resolve<NoDependenciesClass>();
            var obj2 = box.Resolve<NoDependenciesClass>();
            Assert.That(ReferenceEquals(obj1, obj2), Is.False);
        }
        public void DefaultLifeStyleIsSingleForContainerByInterface()
        {
            var box = new Box();
            box.Register<ISomething, Something>();

            var obj1 = box.Resolve<ISomething>();
            var obj2 = box.Resolve<ISomething>();
            Assert.That(ReferenceEquals(obj1, obj2), Is.True);
        }
        public void DefaultLifeStyleIsSingleForContainerByClass()
        {
            var box = new Box();
            box.Register<NoDependenciesClass>();

            var obj1 = box.Resolve<NoDependenciesClass>();
            var obj2 = box.Resolve<NoDependenciesClass>();
            Assert.That(ReferenceEquals(obj1, obj2), Is.True);
        }
Exemple #11
0
		private static Box CreateBox()
		{
			var result = new Box();
			result.Register<ISettingsService, SettingsService>();
			result.Register<IRecentFilesService, RecentFilesService>();
			result.Register<IMathService, MathService>();
			result.Register<IDataService, DataService>();
			result.Register<ITaskService, TaskService>();
			result.Register<MainForm>();
			result.Register<IMainPresenter, MainPresenter>();

			return result;
		}
 public void ResolvingByClassIfRegisteredByInterfaceThrowsException()
 {
     var box = new Box();
     box.Register<ISomething, Something>();
     Assert.That(() => box.Resolve<Something>(), Throws.InstanceOf<TypeNotFoundException>());
 }
        public void NewPerResolveLifeStyleTestByInterface()
        {
            var box = new Box();
            box.Register<ISomething, Something>(LifeStyle.NewPerResolve);

            var obj1 = box.Resolve<ISomething>();
            var obj2 = box.Resolve<ISomething>();
            Assert.That(ReferenceEquals(obj1, obj2), Is.False);
        }