本文整理汇总了C#中StructureMap.Pipeline.Instance类的典型用法代码示例。如果您正苦于以下问题:C# Instance类的具体用法?C# Instance怎么用?C# Instance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instance类属于StructureMap.Pipeline命名空间,在下文中一共展示了Instance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindObject
public override object FindObject(Type pluginType, Instance instance)
{
_dependencyStack.Push(new BuildDependency(pluginType, instance));
try
{
//clearBuildStack();
return base.FindObject(pluginType, instance);
}
catch (StructureMapException ex)
{
_dependencyStack.Pop();
// Don't log exceptions for inline instances. I
// think it would cause more confusion that not
// because the name is a Guid
if (!_explicitInstances.Contains(instance))
{
throw;
}
_errors.LogError(instance, pluginType, ex, _dependencyStack);
throw;
}
}
示例2: Apply
public void Apply(Type pluginType, Instance instance)
{
_policies.Where(x => !instance.AppliedPolicies.Contains(x))
.Each(policy =>
{
try
{
policy.Apply(pluginType, instance);
}
finally
{
instance.AppliedPolicies.Add(policy);
}
});
var configured = instance.As<IConfiguredInstance>();
if (configured != null)
{
configured.Constructor.GetParameters()
.Each(param => param.ForAttribute<StructureMapAttribute>(att => att.Alter(configured, param)));
configured.SettableProperties()
.Each(prop => prop.ForAttribute<StructureMapAttribute>(att => att.Alter(configured, prop)));
}
}
示例3: DetermineInterceptors
public IEnumerable<IInterceptor> DetermineInterceptors(Type pluginType, Instance instance)
{
if (pluginType == typeof(IService))
{
yield return new FuncInterceptor<IService>((context, service) => new DecoratorService(instance.Name, service));
}
}
示例4: ValidationError
public ValidationError(Type pluginType, Instance instance, Exception exception, MethodInfo method)
{
PluginType = pluginType;
Instance = instance;
Exception = exception;
MethodName = method.Name;
}
示例5: FillTypeInto
public void FillTypeInto(Type pluginType, Instance instance)
{
if (!_instances.ContainsKey(pluginType))
{
_instances.Add(pluginType, instance);
}
}
示例6: BuildPlan
/// <summary>
/// FOR TESTING ONLY!
/// </summary>
/// <param name="pluginType"></param>
/// <param name="instance"></param>
/// <param name="inner"></param>
/// <param name="interceptionPlan"></param>
public BuildPlan(Type pluginType, Instance instance, IDependencySource inner, IInterceptionPlan interceptionPlan)
{
_pluginType = pluginType;
_instance = instance;
_inner = inner;
_interceptionPlan = interceptionPlan;
}
示例7: Has
public bool Has(Type pluginType, Instance instance)
{
return _lock.Read(() => {
var key = instance.InstanceKey(pluginType);
return _objects.ContainsKey(key);
});
}
示例8: Get
public object Get(Type pluginType, Instance instance, IBuildSession session)
{
object result = null;
int key = instance.InstanceKey(pluginType);
_lock.EnterUpgradeableReadLock();
if (_objects.ContainsKey(key))
{
result = _objects[key];
_lock.ExitUpgradeableReadLock();
}
else
{
_lock.EnterWriteLock();
try
{
result = buildWithSession(pluginType, instance, session);
_objects.Add(key, result);
}
finally
{
_lock.ExitWriteLock();
}
}
return result;
}
示例9: LogError
public void LogError(
Instance instance,
Type pluginType,
StructureMapException ex,
IEnumerable<BuildDependency> dependencies)
{
if (_buildErrors.ContainsKey(instance))
{
BuildError existingError = _buildErrors[instance];
addDependenciesToError(instance, dependencies, existingError);
}
if (_brokenInstances.Contains(instance))
{
return;
}
InstanceToken token = ((IDiagnosticInstance) instance).CreateToken();
var error = new BuildError(pluginType, instance);
error.Exception = ex;
_buildErrors.Add(instance, error);
addDependenciesToError(instance, dependencies, error);
}
示例10: DetermineInterceptors
public IEnumerable<IInterceptor> DetermineInterceptors(Type pluginType, Instance instance)
{
if (MatchesType(instance.ReturnedType))
{
Expression<Action<IContext, object>> register = (c, o) => c.GetInstance<IEventPublisher>().Subscribe(o);
yield return new ActivatorInterceptor<object>(register);
}
}
示例11: WrapFunc
public static Expression WrapFunc(Type returnType, Instance instance, Expression inner)
{
var push = Expression.Call(Parameters.Session, PushMethod, Expression.Constant(instance));
var block = Expression.Block(returnType, push, inner);
var pop = Expression.Call(Parameters.Session, PopMethod);
return Expression.TryFinally(block, pop);
}
示例12: Apply
/// <summary>
/// Applies explicit configuration to an IConfiguredInstance
/// </summary>
/// <param name="pluginType"></param>
/// <param name="instance"></param>
public void Apply(Type pluginType, Instance instance)
{
var configured = instance as IConfiguredInstance;
if (configured != null)
{
apply(pluginType, configured);
}
}
示例13: Eject
public void Eject(Type pluginType, Instance instance)
{
var key = new InstanceKey(instance, pluginType);
if (!_objects.Has(key)) return;
var disposable = _objects[key] as IDisposable;
_objects.Remove(key);
disposable.SafeDispose();
}
示例14: DetermineInterceptors
public IEnumerable<IInterceptor> DetermineInterceptors(Type pluginType, Instance instance)
{
if (_filter(pluginType, instance))
{
var interceptorType = typeof(DynamicProxyInterceptor<>).MakeGenericType(pluginType);
var interceptor = (IInterceptor)Activator.CreateInstance(interceptorType, new object[] { _interceptionBehaviors });
yield return interceptor;
}
}
示例15: Get
public object Get(Type pluginType, Instance instance, IBuildSession session)
{
var @object = session.BuildNewInSession(pluginType, instance);
if (@object is IDisposable)
{
_tracked.Add(@object);
}
return @object;
}