public object Get(IContextual contextual, ICreationalContext creationalContext) { if (!IsActive) { throw new ContextNotActiveException(Scope); } var store = ComponentStore; if (store == null) { return(null); } if (contextual == null) { throw new ArgumentNullException("contextual"); } var contextualStore = Container.Instance.ContextualStore; var id = contextualStore.PutIfAbsent(contextual); var instance = store.GetOrPut(id, _ => { var i = contextual.Create(creationalContext); return(new SerializableContextualInstance(contextual, i, creationalContext, contextualStore)); }); if (instance != null) { return(instance.Instance); } return(null); }
public override void Destroy(object instance, ICreationalContext creationalContext) { try { var disposable = instance as IDisposable; if (disposable != null) { disposable.Dispose(); } // WELD-1010 hack? var context = creationalContext as IWeldCreationalContext; if (context != null) { context.Release(this, instance); } else { creationalContext.Release(); } } catch (Exception e) { // TODO log.error(ERROR_DESTROYING, this, instance); // TODO xLog.throwing(Level.DEBUG, e); throw; } }
public object InvokeWithSpecialValue(ICreationalContext creationalContext, object specialParameterValue) { var parameters = _injectionPoints .Select(x => x == null ? specialParameterValue : x.GetValue(creationalContext)) .ToArray(); return(Invoke(parameters, creationalContext)); }
public object Invoke(ICreationalContext creationalContext) { if (SpecialParameter != null) { throw new InvalidOperationException("Must be invoked with InvokeWithSpecialValue"); } return(Invoke(GetParameterValues(creationalContext), creationalContext)); }
public Instance(WeldComponentManager manager, IQualifier[] qualifiers, IWeldComponent[] components, ICreationalContext creationalContext) { _qualifiers = qualifiers; _components = components; _creationalContext = creationalContext; _currentInjectionPoint = manager.GetService <CurrentInjectionPoint>(); _injectionPoint = _currentInjectionPoint.Peek(); }
public Task InvokeAsyncWithSpecialValue(ICreationalContext creationalContext, object specialParameterValue) { var result = InvokeWithSpecialValue(creationalContext, specialParameterValue); if (IsAsync) { return((Task)result); } return(Task.FromResult(result)); }
public object GetInjectableReference(IInjectionPoint injectionPoint, ICreationalContext creationalContext) { var proxyTypes = new [] { injectionPoint.ComponentType }; var weldIp = injectionPoint as IWeldInjetionPoint; if (weldIp != null && weldIp.Unwraps) { proxyTypes = new Type[0]; } return(GetReference(injectionPoint, injectionPoint.Component, creationalContext, proxyTypes)); }
public override void Destroy(object instance, ICreationalContext creationalContext) { // WELD-1010 hack? var context = creationalContext as IWeldCreationalContext; if (context != null) { context.Release(this, instance); } else { creationalContext.Release(); } }
public object Get(IContextual contextual, ICreationalContext creationalContext) { if (!IsActive) { throw new ContextNotActiveException(Scope); } if (creationalContext != null) { var instance = contextual.Create(creationalContext); var weldContext = creationalContext as IWeldCreationalContext; if (weldContext != null) { AddDependentInstance(instance, contextual, weldContext); } return(instance); } return(null); }
public void Inject(object target, ICreationalContext context) { _lazyInjectPlan.Value(target, context); }
public override void Destroy(object instance, ICreationalContext creationalContext) { }
public object GetValue(ICreationalContext context) { return(_lazyGetValuePlan.Value(context)); }
private object GetReference(IInjectionPoint injectionPoint, IComponent component, ICreationalContext creationalContext, params Type[] proxyTypes) { var pushInjectionPoint = injectionPoint != null && injectionPoint.ComponentType != typeof(IInjectionPoint); try { if (pushInjectionPoint) { _currentInjectionPoint.Push(injectionPoint); } if (proxyTypes.Any() && component.IsProxyRequired) { foreach (var proxyType in proxyTypes) { InjectionValidator.ValidateProxiable(proxyType, injectionPoint); } return(CormoProxyGenerator.CreateProxy(proxyTypes, () => { try { if (pushInjectionPoint) { _currentInjectionPoint.Push(injectionPoint); } return GetReference(injectionPoint, component, creationalContext, new Type[0]); } finally { if (pushInjectionPoint) { _currentInjectionPoint.Pop(); } } })); } var context = creationalContext as IWeldCreationalContext; if (context != null) { var incompleteInstance = context.GetIncompleteInstance(component); if (incompleteInstance != null) { return(incompleteInstance); } } creationalContext = creationalContext.GetCreationalContext(component); return(GetContext(component.Scope).Get(component, creationalContext)); } finally { if (pushInjectionPoint) { _currentInjectionPoint.Pop(); } } }
public object GetReference(IComponent component, ICreationalContext creationalContext, params Type[] proxyTypes) { return(GetReference(null, component, creationalContext, proxyTypes)); }
public object Create(ICreationalContext context) { return(Delegate.Create(context)); }
public object InvokeWithInstance(object instance, ICreationalContext creationalContext) { var parameters = GetParameterValues(creationalContext); return(Method.Invoke(Method.IsStatic?null: instance, parameters)); }
protected abstract object Invoke(object[] parameters, ICreationalContext creationalContext);
public InterceptorMethodHandler(WeldComponentManager manager, MethodInfo method, Interceptor[] interceptors, ICreationalContext creationalContext) { _interceptorReferences = new LinkedList <IAroundInvokeInterceptor>( interceptors.Select(x => manager.GetReference(x, creationalContext)) .Cast <IAroundInvokeInterceptor>()); _bindingsLazy = new Lazy <IEnumerable <IInterceptorBinding> >(() => method.GetAnnotations().OfType <IInterceptorBinding>().ToArray()); var returnType = method.ReturnType; if (returnType == typeof(Task)) { _isAsync = true; _taskCaster = TaskCasters.ForVoid(); } else if (returnType.IsGenericType) { var genericType = returnType.GetGenericTypeDefinition(); if (genericType == typeof(Task <>)) { _isAsync = true; _taskCaster = TaskCasters.ForType(returnType.GetGenericArguments()[0]); } } }
public object Create(ICreationalContext context) { return(_lazyBuildPlan.Value(context)); }
public abstract void Destroy(object instance, ICreationalContext creationalContext);
protected override object Invoke(object[] parameters, ICreationalContext creationalContext) { var containingObject = Method.IsStatic ? null : Component.Manager.GetReference(Component, creationalContext); return(Method.Invoke(containingObject, parameters)); }
protected override object Invoke(object[] parameters, ICreationalContext creationalContext) { return(Activator.CreateInstance(_ctor.DeclaringType, parameters)); }
public void Destroy(object instance, ICreationalContext creationalContext) { Delegate.Destroy(instance, creationalContext); }
public CormoDependencyResolver(IComponentManager componentManager, ICreationalContext creationalContext) { _componentManager = componentManager; _creationalContext = creationalContext; }
public object[] GetParameterValues(ICreationalContext creationalContext) { return(_injectionPoints .Select(x => x.GetValue(creationalContext)) .ToArray()); }
public override void Destroy(object instance, ICreationalContext creationalContext) { // TODO DisposeAttribute }
public SerializableContextualInstance(IContextual contextual, object instance, ICreationalContext creationalContext, IContextualStore contextualStore) { Contextual = new SerializableContextual(contextual, contextualStore); Instance = instance; CreationalContext = creationalContext; }