当前位置: 首页>>代码示例>>C#>>正文


C# Defaults.DefaultPicoContainer类代码示例

本文整理汇总了C#中PicoContainer.Defaults.DefaultPicoContainer的典型用法代码示例。如果您正苦于以下问题:C# DefaultPicoContainer类的具体用法?C# DefaultPicoContainer怎么用?C# DefaultPicoContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DefaultPicoContainer类属于PicoContainer.Defaults命名空间,在下文中一共展示了DefaultPicoContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NanoContainerCanBeBuiltFromCodeOnTheFly

		public void NanoContainerCanBeBuiltFromCodeOnTheFly()
		{
			string code = @"
				using PicoContainer;
				using PicoContainer.Defaults;
				namespace Test 
				{
					public class NameTranslator 
					{
						private IPicoContainer parent;
						public IPicoContainer Parent {
							set { parent = value; } 
						}
				
						public IMutablePicoContainer Compose() {
							DefaultPicoContainer p = new DefaultPicoContainer(parent);
							p.RegisterComponentInstance(10, 1000);
							return p; 
						}
					}
				}";

			IMutablePicoContainer parent = new DefaultPicoContainer();
			ContainerBuilderFacade cbf = new CSharpContainerBuilderFacade(ScriptFixture.BuildStreamReader(code));
			IPicoContainer pico = cbf.Build(parent, new ArrayList());

			Assert.IsNotNull(pico);
			Assert.AreSame(parent, pico.Parent);
			Assert.AreEqual(1000, pico.GetComponentInstance(10));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:30,代码来源:CSharpContainerBuilderTestCase.cs

示例2: ConstantParameterRespectsExpectedType

		public void ConstantParameterRespectsExpectedType()
		{
			IMutablePicoContainer picoContainer = new DefaultPicoContainer();
			IParameter parameter = new ConstantParameter(new SimpleTouchable());
			IComponentAdapter adapter = picoContainer.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));
			Assert.IsFalse(parameter.IsResolvable(picoContainer, adapter, typeof (TestFixtureAttribute)));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:7,代码来源:ParameterTestCase.cs

示例3: NanoContainerCanBeBuiltFromCodeOnTheFly

		public void NanoContainerCanBeBuiltFromCodeOnTheFly()
		{
			// Boo relies on indentation so start at column 1. MUST NOT BE REFORMATTED
			string code = @"
import PicoContainer from PicoContainer
import PicoContainer.Defaults from PicoContainer

class BooInjector:
	
	[Property(Parent)]
	_parent as IPicoContainer
	
	def Compose() as IMutablePicoContainer:
		p = DefaultPicoContainer(_parent)
		p.RegisterComponentInstance(10, 1000)
		return p

			";

			IMutablePicoContainer parent = new DefaultPicoContainer();
			ContainerBuilderFacade cbf = new BooContainerBuilderFacade(ScriptFixture.BuildStreamReader(code));
			IPicoContainer pico = cbf.Build(parent, new ArrayList());

			Assert.IsNotNull(pico);
			Assert.AreSame(parent, pico.Parent);
			Assert.AreEqual(1000, pico.GetComponentInstance(10));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:27,代码来源:BooContainerBuilderTestCase.cs

示例4: ConstantParameter

 public void ConstantParameter()
 {
     Object value = new Object();
     ConstantParameter parameter = new ConstantParameter(value);
     IMutablePicoContainer picoContainer = new DefaultPicoContainer();
     Assert.AreSame(value, parameter.ResolveInstance(picoContainer, null, typeof (object)));
 }
开发者ID:smmckay,项目名称:picocontainer,代码行数:7,代码来源:ParameterTestCase.cs

示例5: DEF_verifyWithoutDependencyWorks

		public void DEF_verifyWithoutDependencyWorks()
		{
			IMutablePicoContainer picoContainer = new DefaultPicoContainer(CreateDefaultComponentAdapterFactory());
			IComponentAdapter componentAdapter = prepDEF_verifyWithoutDependencyWorks(picoContainer);
			Assert.AreSame(GetComponentAdapterType(), componentAdapter.GetType());
			componentAdapter.Verify(picoContainer);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:7,代码来源:AbstractComponentAdapterTestCase.cs

示例6: WrapComponentInstances

        protected virtual IPicoContainer WrapComponentInstances(Type decoratingComponentAdapterClass,
                                                                IPicoContainer picoContainer,
                                                                object[] wrapperDependencies)
        {
            Assert.IsTrue(typeof (DecoratingComponentAdapter).IsAssignableFrom(decoratingComponentAdapterClass));
            IMutablePicoContainer mutablePicoContainer = new DefaultPicoContainer();
            int size = (wrapperDependencies != null ? wrapperDependencies.Length : 0) + 1;
            ICollection allComponentAdapters = picoContainer.ComponentAdapters;

            foreach (object adapter in allComponentAdapters)
            {
                IParameter[] parameters = new IParameter[size];
                parameters[0] = new ConstantParameter(adapter);
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = new ConstantParameter(wrapperDependencies[i - 1]);
                }
                IMutablePicoContainer instantiatingPicoContainer =
                    new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
                instantiatingPicoContainer.RegisterComponentImplementation("decorator", decoratingComponentAdapterClass,
                                                                           parameters);
                mutablePicoContainer.RegisterComponent(
                    (IComponentAdapter) instantiatingPicoContainer.GetComponentInstance("decorator"));
            }
            return mutablePicoContainer;
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:26,代码来源:AbstractComponentAdapterTestCase.cs

示例7: Compose

		public IMutablePicoContainer Compose()
		{
			DefaultPicoContainer p = new DefaultPicoContainer(parent);

			p.RegisterComponentInstance("hello", "C#");
			return p;
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:7,代码来源:test.cs

示例8: GetDefaultPicoContainer

		private IMutablePicoContainer GetDefaultPicoContainer()
		{
			IMutablePicoContainer mpc = new DefaultPicoContainer();
			mpc.RegisterComponentImplementation(typeof (Bowl));
			mpc.RegisterComponentImplementation(typeof (Cod));
			mpc.RegisterComponentImplementation(typeof (Shark));
			return mpc;
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:8,代码来源:CollectionComponentParameterTestCase.cs

示例9: ComponentParameterRespectsExpectedType

 public void ComponentParameterRespectsExpectedType()
 {
     IMutablePicoContainer picoContainer = new DefaultPicoContainer();
     IComponentAdapter adapter =
         picoContainer.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));
     Assert.IsNull(
         ComponentParameter.DEFAULT.ResolveInstance(picoContainer, adapter, typeof (TestFixtureAttribute)));
 }
开发者ID:smmckay,项目名称:picocontainer,代码行数:8,代码来源:ParameterTestCase.cs

示例10: ContainerCanBeBuiltWithParent

		public void ContainerCanBeBuiltWithParent()
		{
			IMutablePicoContainer parent = new DefaultPicoContainer();
			IPicoContainer pico = BuildContainer(new VBBuilder(GetStreamReader(@"NanoContainer.Tests.TestScripts.test.vb")), parent, new ArrayList());
			Assert.IsNotNull(pico);
			Assert.AreSame(parent, pico.Parent);
			Assert.AreEqual("VB", pico.GetComponentInstance("hello"));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:8,代码来源:VBContainerBuilderTestCase.cs

示例11: DEF_verifyDoesNotInstantiate

		public void DEF_verifyDoesNotInstantiate()
		{
			IMutablePicoContainer picoContainer = new DefaultPicoContainer(CreateDefaultComponentAdapterFactory());
			IComponentAdapter componentAdapter = prepDEF_verifyDoesNotInstantiate(picoContainer);
			Assert.AreSame(GetComponentAdapterType(), componentAdapter.GetType());
			IComponentAdapter notInstantiatablecomponentAdapter = new NotInstantiatableComponentAdapter(componentAdapter);
			IPicoContainer wrappedPicoContainer = WrapComponentInstances(typeof (NotInstantiatableComponentAdapter), picoContainer, null);
			notInstantiatablecomponentAdapter.Verify(wrappedPicoContainer);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:9,代码来源:AbstractComponentAdapterTestCase.cs

示例12: ComponentParameterExcludesSelf

		public void ComponentParameterExcludesSelf()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			IComponentAdapter adapter = pico.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

			Assert.IsNotNull(pico.GetComponentInstance(typeof (ITouchable)));
			ITouchable touchable = (ITouchable) ComponentParameter.DEFAULT.ResolveInstance(pico, adapter, typeof (ITouchable));
			Assert.IsNull(touchable);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:9,代码来源:ParameterTestCase.cs

示例13: ContainerCanBeBuiltWithParent

		public void ContainerCanBeBuiltWithParent()
		{
			IMutablePicoContainer parent = new DefaultPicoContainer();
			ContainerBuilderFacade cbf = new JSharpContainerBuilderFacade(GetStreamReader(@"NanoContainer.Tests.TestScripts.test.java"));
			IPicoContainer pico = cbf.Build(parent, new ArrayList());
			Assert.IsNotNull(pico);
			Assert.AreSame(parent, pico.Parent);
			Assert.AreEqual("J#", pico.GetComponentInstance("hello"));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:9,代码来源:JSharpContainerBuilderTestCase.cs

示例14: DefaultNanoContainer

		public DefaultNanoContainer(StreamReader composition, String builderClass)
		{
			DefaultReflectionContainerAdapter defaultReflectionContainerAdapter;
			DefaultPicoContainer dpc = new DefaultPicoContainer();
			dpc.RegisterComponentInstance(composition);

			defaultReflectionContainerAdapter = new DefaultReflectionContainerAdapter(dpc);
			IComponentAdapter componentAdapter = defaultReflectionContainerAdapter.RegisterComponentImplementation(builderClass);
			containerBuilder = (ScriptedContainerBuilder) componentAdapter.GetComponentInstance(dpc);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:10,代码来源:NanoContainer.cs

示例15: DefaultPicoContainerReturnsNewInstanceForEachCallWhenUsingTransientIComponentAdapter

		public void DefaultPicoContainerReturnsNewInstanceForEachCallWhenUsingTransientIComponentAdapter()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			picoContainer.RegisterComponentImplementation(typeof (Service));
			picoContainer.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof (TransientComponent), typeof (TransientComponent)));
			TransientComponent c1 = (TransientComponent) picoContainer.GetComponentInstance(typeof (TransientComponent));
			TransientComponent c2 = (TransientComponent) picoContainer.GetComponentInstance(typeof (TransientComponent));
			Assert.IsFalse(c1.Equals(c2));
			Assert.AreSame(c1.service, c2.service);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:10,代码来源:TransientComponentAdapterTestCase.cs


注:本文中的PicoContainer.Defaults.DefaultPicoContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。