コード例 #1
0
		public void RegisterFuncByTypeTest()
		{
			SimpleSecondaryExportLocator resolver = new SimpleSecondaryExportLocator();

			resolver.AddResolveValue(() => new BasicService());

			object returnValue =
				resolver.Locate(new FauxInjectionScope(), new FauxInjectionContext(), null, typeof(BasicService), null, null);

			Assert.NotNull(returnValue);
			Assert.IsType(typeof(BasicService), returnValue);
		}
コード例 #2
0
		public void InitValueTest()
		{
			SimpleSecondaryExportLocator resolver = new SimpleSecondaryExportLocator(
				new Dictionary<string, object>
				{
					{ "BasicService", new BasicService() }
				});

			object returnValue =
				resolver.Locate(new FauxInjectionScope(), new FauxInjectionContext(), "BasicService", null, null, null);

			Assert.NotNull(returnValue);
			Assert.IsType(typeof(BasicService), returnValue);
		}
コード例 #3
0
		public void BasicResolverTest()
		{
			DependencyInjectionContainer container = new DependencyInjectionContainer();

			SimpleSecondaryExportLocator resolver = new SimpleSecondaryExportLocator();

			container.AddSecondaryLocator(resolver);
			container.Configure(c => c.Export<ImportConstructorService>().As<IImportConstructorService>());

			resolver.AddResolveValue((IBasicService)new BasicService());

			IImportConstructorService constructorService = container.Locate<IImportConstructorService>();

			Assert.NotNull(constructorService);
		}
コード例 #4
0
		public void ResolveValueTypeFromChildTest()
		{
			DependencyInjectionContainer container = new DependencyInjectionContainer();

			SimpleSecondaryExportLocator resolver = new SimpleSecondaryExportLocator();

			container.AddSecondaryLocator(resolver);
			container.Configure(c => c.Export<WithCtorParamClass>());

			resolver.AddResolveValue(() => (IBasicService)new BasicService());
			resolver.AddResolveValue("stringParam", "Hello");
			resolver.AddResolveValue("intParam", 10);

			WithCtorParamClass paramClass = container.Locate<WithCtorParamClass>();

			Assert.NotNull(paramClass);
			Assert.Equal("Hello", paramClass.StringParam);
			Assert.Equal(10, paramClass.IntParam);
		}