本文整理汇总了C#中IPicoContainer类的典型用法代码示例。如果您正苦于以下问题:C# IPicoContainer类的具体用法?C# IPicoContainer怎么用?C# IPicoContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPicoContainer类属于命名空间,在下文中一共展示了IPicoContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveInstance
/// <summary>
/// Resolve the parameter for the expected type. The method will return <code>null</code>
/// If the expected type is not one of the collection types {@link Array},
/// {@link Collection}or {@link Map}. An empty collection is only a valid resolution, if
/// the <code>emptyCollection</code> flag was set.
/// </summary>
/// <param name="container"></param>
/// <param name="adapter"></param>
/// <param name="expectedType"></param>
/// <returns>the instance of the collection type or <code>null</code></returns>
public Object ResolveInstance(IPicoContainer container, IComponentAdapter adapter, Type expectedType)
{
// type check is done in isResolvable
Object result = null;
Type collectionType = GetCollectionType(expectedType);
if (collectionType != null)
{
IDictionary dictionary = GetMatchingComponentAdapters(container, adapter, componentKeyType, GetValueType(expectedType));
if (typeof (Array).IsAssignableFrom(collectionType))
{
result = GetArrayInstance(container, expectedType, dictionary);
}
else if (typeof (IDictionary).IsAssignableFrom(collectionType))
{
result = GetDictionaryInstance(container, expectedType, dictionary);
}
else if (typeof (ICollection).IsAssignableFrom(collectionType))
{
result = GetCollectionInstance(container, expectedType, dictionary);
}
else
{
throw new PicoIntrospectionException(expectedType.Name + " is not a collective type");
}
}
return result;
}
示例2: 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;
}
示例3: ImplementationHidingPicoContainer
/// <summary>
/// Creates a new container with a parent container.
/// </summary>
/// <param name="caf"></param>
/// <param name="parent"></param>
/// <param name="lifecycleManager"></param>
public ImplementationHidingPicoContainer(IComponentAdapterFactory caf, IPicoContainer parent,
ILifecycleManager lifecycleManager)
: base(new DefaultPicoContainer(caf, parent, lifecycleManager))
{
this.caf = caf;
this.lifecycleManager = lifecycleManager;
}
示例4: CachingPicoContainer
/// <summary>
/// Creates a new container with a parent container.
/// </summary>
/// <param name="caf"></param>
/// <param name="parent"></param>
/// <param name="lifecycleManager"></param>
public CachingPicoContainer(CachingComponentAdapterFactory caf, IPicoContainer parent,
ILifecycleManager lifecycleManager)
: base(new DefaultPicoContainer(caf, parent, lifecycleManager))
{
this.lifecycleManager = lifecycleManager;
this.caf = caf;
}
示例5: CreatePicoContainer
protected override IMutablePicoContainer CreatePicoContainer(IPicoContainer parent,
ILifecycleManager lifecycleManager)
{
return
new ImplementationHidingCachingPicoContainer(
new CachingComponentAdapterFactory(new DefaultComponentAdapterFactory()), parent, lifecycleManager);
}
示例6: CreateContainerFromScript
protected virtual IMutablePicoContainer CreateContainerFromScript(IPicoContainer parentContainer,
IList assemblies)
{
IScript script = CreateScript(assemblies);
script.Parent = parentContainer;
return script.Compose();
}
示例7: GetComponentInstance
public override Object GetComponentInstance(IPicoContainer container)
{
Object componentKey = Delegate.ComponentKey;
Type[] types;
if (componentKey is Type && ((Type) Delegate.ComponentKey).IsInterface)
{
types = new Type[] {(Type) Delegate.ComponentKey};
}
else if (componentKey is Type[])
{
types = (Type[]) componentKey;
}
else
{
if (strict)
{
throw new PicoIntrospectionException("In strict mode, "
+ GetType().Name
+
" only allows components registered with interface keys (System.Type or System.Type[])");
}
return Delegate.GetComponentInstance(container);
}
return CreateProxy(types, container);
}
示例8: ImplementationHidingCachingPicoContainer
private ImplementationHidingCachingPicoContainer(IPicoContainer parent, CachingComponentAdapterFactory caf,
ILifecycleManager lifecycleManager)
: base(new ImplementationHidingPicoContainer(caf, parent, lifecycleManager))
{
this.caf = caf;
this.lifecycleManager = lifecycleManager;
}
示例9: CreatePicoContainer
protected override IMutablePicoContainer CreatePicoContainer(IPicoContainer parent)
{
return
new DefaultPicoContainer(
new CachingComponentAdapterFactory(
new ImplementationHidingComponentAdapterFactory(
new ConstructorInjectionComponentAdapterFactory(), false)), parent);
}
开发者ID:smmckay,项目名称:picocontainer,代码行数:8,代码来源:ImplementationHidingWithDefaultPicoContainerTestCase.cs
示例10: GetComponentInstance
/// <summary>
/// Gets the component instance. Only one instance is created of the type
/// </summary>
/// <returns>a component instance</returns>
/// <exception cref="PicoContainer.PicoInitializationException">if the component could not be instantiated.</exception>
/*public override object ComponentInstance
{
get
{
if (instanceReference.Get() == null)
{
instanceReference.Set(base.ComponentInstance);
}
return instanceReference.Get();
}
}*/
public override object GetComponentInstance(IPicoContainer container)
{
if (instanceReference.Get() == null)
{
instanceReference.Set(base.GetComponentInstance(container));
}
return instanceReference.Get();
}
示例11: GetComponentInstance
public override object GetComponentInstance(IPicoContainer container)
{
if (constructorInjectionGuard == null)
{
constructorInjectionGuard = new ConstructorInjectionGuard(this, container);
}
return constructorInjectionGuard.Observe(ComponentImplementation);
}
示例12: Dispose
public virtual void Dispose(IPicoContainer node)
{
IList disposables = node.GetComponentInstancesOfType(typeof (IDisposable));
for (int i = disposables.Count - 1; 0 <= i; i--)
{
DoMethod(disposeMethod, disposables[i]);
}
}
示例13: BuildContainer
protected IPicoContainer BuildContainer(ScriptedContainerBuilder builder, IPicoContainer parentContainer, IList assemblies)
{
SimpleReference sr = new SimpleReference();
SimpleReference pr = new SimpleReference();
pr.Set(parentContainer);
builder.BuildContainer(sr, pr, assemblies);
return (IPicoContainer) sr.Get();
}
示例14: Start
public virtual void Start(IPicoContainer node)
{
IList startables = node.GetComponentInstancesOfType(typeof (IStartable));
foreach (object startable in startables)
{
DoMethod(startMethod, startable);
}
}
示例15: Verify
public override void Verify(IPicoContainer container)
{
if (verifyingGuard == null)
{
verifyingGuard = new DefaultVerifyingGuard(this, container);
}
verifyingGuard.Observe(ComponentImplementation);
}