Пример #1
0
		public void CanRegisterAndResolveInstance()
		{
			// Arrange
			var instance = new MyClassImplementingInterface();
			_containerBuilder.ForInstanceOfType<IMyInterface>().Register(instance);
			IDependencyResolver container = _containerBuilder.Build();

			// Act
			var result = container.Resolve<IMyInterface>();

			// Assert
			Assert.IsNotNull(result);
			Assert.IsInstanceOfType(result, typeof(IMyInterface));
		}
Пример #2
0
		public void CanRegisterAndResolveInstanceByName()
		{
			// Arrange
			var instance = new MyClassImplementingInterface();
			var instance2 = new MyClassImplementingInterface("this is a difference instance");
			_containerBuilder.ForInstanceOfType<IMyInterface>().Register(instance);
			_containerBuilder.ForInstanceOfType<IMyInterface>().Register(instance2, "named");
			IDependencyResolver container = _containerBuilder.Build();

			// Act
			var result1 = container.Resolve<IMyInterface>();
			var result2 = container.Resolve<IMyInterface>("named");

			// Assert
			Assert.IsNotNull(result1);
			Assert.IsInstanceOfType(result1, typeof(IMyInterface));
			Assert.IsNotNull(result2);
			Assert.IsInstanceOfType(result2, typeof(IMyInterface));
			Assert.AreNotSame(result1, result2);
		}