/// <summary> /// This method is called by the export strategy when attempting to locate an export /// </summary> /// <param name="creationDelegate"></param> /// <param name="exportStrategyScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope exportStrategyScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (instance.Value != null) { return instance.Value; } IDisposalScope contextdisposalScope = injectionContext.DisposalScope; IInjectionScope requestingScope = injectionContext.RequestingScope; injectionContext.DisposalScope = exportStrategyScope; injectionContext.RequestingScope = exportStrategyScope; object instanceValue = creationDelegate(exportStrategyScope, injectionContext); injectionContext.DisposalScope = contextdisposalScope; injectionContext.RequestingScope = requestingScope; instance.Value = instanceValue; IDisposable disposable = instanceValue as IDisposable; if (disposable != null) { disposalScope.AddDisposable(disposable); } return instance.Value; }
public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope injectionScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { IDictionary<object, object> items = OperationContext.Current.Items(); object returnValue = items[uniqueRequestKey]; if (returnValue == null) { IDisposalScope disposalScope = injectionContext.DisposalScope; IInjectionScope requestingScope = injectionContext.RequestingScope; injectionContext.DisposalScope = OperationContext.Current.DisposalScope(); injectionContext.RequestingScope = exportStrategy.OwningScope; returnValue = creationDelegate(exportStrategy.OwningScope, injectionContext); injectionContext.DisposalScope = disposalScope; injectionContext.RequestingScope = requestingScope; if (returnValue != null) { items[uniqueRequestKey] = returnValue; } } return returnValue; }
public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope injectionScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { object returnValue = null; if (HttpContext.Current != null) { returnValue = HttpContext.Current.Items[uniqueId]; } if (returnValue == null) { IDisposalScope disposalScope = injectionContext.DisposalScope; IInjectionScope requestingScope = injectionContext.RequestingScope; injectionContext.DisposalScope = MVCDisposalScopeProvider.GetDisposalScope(); injectionContext.RequestingScope = exportStrategy.OwningScope; returnValue = creationDelegate(exportStrategy.OwningScope, injectionContext); injectionContext.DisposalScope = disposalScope; injectionContext.RequestingScope = requestingScope; if (returnValue != null && HttpContext.Current != null) { HttpContext.Current.Items[uniqueId] = returnValue; } } return returnValue; }
/// <summary> /// Default constructor /// </summary> /// <param name="exportDelegateInfo"></param> /// <param name="activationDelegate"></param> /// <param name="exportStrategy"></param> /// <param name="owningScope"></param> public FuncCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, ExportActivationDelegate activationDelegate, IExportStrategy exportStrategy, IInjectionScope owningScope) : base(exportDelegateInfo,exportStrategy, owningScope) { exportActivationDelegate = activationDelegate; }
/// <summary> /// This method is called by the export strategy when attempting to locate an export /// </summary> /// <param name="creationDelegate"></param> /// <param name="injectionScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope injectionScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (lifestyleContainer == null) { lifestyleContainer = LocateContainer(exportStrategy.OwningScope, injectionContext); } return lifestyleContainer.Locate(creationDelegate, injectionScope, injectionContext, exportStrategy); }
/// <summary> /// This method is called by the export strategy when attempting to locate an export /// </summary> /// <param name="creationDelegate"></param> /// <param name="exportStrategyScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope exportStrategyScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { object returnValue = null; if (intanceRef != null) { returnValue = intanceRef.Target; } if (returnValue == null) { lock (lockObject) { if (intanceRef != null) { returnValue = intanceRef.Target; } if (returnValue == null) { IDisposalScope disposalScope = injectionContext.DisposalScope; IInjectionScope requeInjectionScope = injectionContext.RequestingScope; // null scope because weak exports can't have injectionContext.DisposalScope = null; injectionContext.RequestingScope = exportStrategyScope; returnValue = creationDelegate(exportStrategyScope, injectionContext); injectionContext.DisposalScope = disposalScope; injectionContext.RequestingScope = requeInjectionScope; if (returnValue != null) { intanceRef = new WeakReference(returnValue); } } } } return returnValue; }
/// <summary> /// This method is called by the export strategy when attempting to locate an export /// </summary> /// <param name="creationDelegate"></param> /// <param name="exportStrategyScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope exportStrategyScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { object returnValue = injectionContext.RequestingScope.GetExtraData(uniqueId); if (returnValue == null) { IInjectionScope requestScope = injectionContext.RequestingScope; returnValue = creationDelegate(exportStrategyScope, injectionContext); requestScope.SetExtraData(uniqueId, returnValue); } return returnValue; }
/// <summary> /// Creates an instance in a singleton scope /// </summary> /// <param name="creationDelegate"></param> /// <param name="exportStrategyScope"></param> /// <param name="injectionContext"></param> /// <returns></returns> public static object CreateInSingletonScope(ExportActivationDelegate creationDelegate, IInjectionScope exportStrategyScope, IInjectionContext injectionContext) { object returnValue = null; IDisposalScope disposalScope = injectionContext.DisposalScope; IInjectionScope requestingScope = injectionContext.RequestingScope; injectionContext.DisposalScope = exportStrategyScope; injectionContext.RequestingScope = exportStrategyScope; returnValue = creationDelegate(exportStrategyScope, injectionContext); injectionContext.DisposalScope = disposalScope; injectionContext.RequestingScope = requestingScope; return returnValue; }
/// <summary> /// This method is called by the export strategy when attempting to locate an export /// </summary> /// <param name="creationDelegate"></param> /// <param name="injectionScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope injectionScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { object returnValue = injectionContext.GetExtraData(key); if (returnValue == null) { returnValue = creationDelegate(injectionScope, injectionContext); if (returnValue != null) { injectionContext.SetExtraData(key, returnValue); } } return returnValue; }
public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope injectionScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { object returnValue = null; IInjectionScope locateScope = FindNamedScope(injectionContext.RequestingScope); if (locateScope == null) { throw new InjectionScopeCouldNotBeFoundException(_namedScope); } returnValue = locateScope.GetExtraData(_uniqueId); if (returnValue != null) { return returnValue; } lock (_lockObject) { returnValue = locateScope.GetExtraData(_uniqueId) ?? SingletonLifestyle.CreateInSingletonScope(creationDelegate, locateScope, injectionContext); if (returnValue != null) { locateScope.SetExtraData(_uniqueId, returnValue); IDisposable disposable = returnValue as IDisposable; if (disposable != null) { locateScope.AddDisposable(disposable); } } } return returnValue; }
/// <summary> /// Method used to invoke an activation delegate /// </summary> /// <param name="exportStrategyScope"></param> /// <param name="activationDelegate"></param> /// <param name="injectionContext"></param> /// <returns></returns> public static object InvokeActivationDelegate(ExportActivationDelegate activationDelegate, IInjectionScope exportStrategyScope, IInjectionContext injectionContext) { return activationDelegate(exportStrategyScope, injectionContext); }
/// <summary> /// This method is called by the export strategy when attempting to locate an export /// </summary> /// <param name="creationDelegate"></param> /// <param name="exportStrategyScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope exportStrategyScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (instance == null) { lock (lockObject) { if (instance == null) { instance = CreateInSingletonScope(creationDelegate, exportStrategy.OwningScope, injectionContext); } } } return instance; }
/// <summary> /// Locate object /// </summary> /// <param name="creationDelegate"></param> /// <param name="injectionScope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public object Locate(ExportActivationDelegate creationDelegate, IInjectionScope injectionScope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { object scopeName = valueDelegate(injectionScope, injectionContext); Tuple<object, IDisposalScope> trackedObject; if (!scopedObjects.TryGetValue(scopeName, out trackedObject)) { IDisposalScope disposalScope = injectionContext.DisposalScope; IInjectionScope requestingScope = injectionContext.RequestingScope; IDisposalScope newDisposalScope = new DisposalScope(); injectionContext.DisposalScope = newDisposalScope; injectionContext.RequestingScope = exportStrategy.OwningScope; object locatedObject = creationDelegate(injectionScope, injectionContext); injectionContext.DisposalScope = disposalScope; injectionContext.RequestingScope = requestingScope; if (locatedObject != null) { trackedObject = new Tuple<object, IDisposalScope>(locatedObject, newDisposalScope); scopedObjects[scopeName] = trackedObject; INotifyWhenDisposed notifyWhenDisposed = scopeName as INotifyWhenDisposed; if (notifyWhenDisposed != null) { notifyWhenDisposed.Disposed += (sender, args) => { scopedObjects.Remove(scopeName); newDisposalScope.Dispose(); }; } return locatedObject; } } else { return trackedObject.Item1; } return null; }
/// <summary> /// Default constructor /// </summary> /// <param name="valueDelegate">value delegate</param> public SingletonPerValueLifestyle(ExportActivationDelegate valueDelegate) { scopedObjects = new SafeDictionary<object, Tuple<object, IDisposalScope>>(); this.valueDelegate = valueDelegate; }
/// <summary> /// Initialize strategy /// </summary> public override void Initialize() { base.Initialize(); Tuple<ExportActivationDelegate, List<ExportStrategyDependency>> activationInfo; if (!delegateDictionary.TryGetValue(_exportType, out activationInfo)) { SimpleCompiledExportDelegate compiledExportDelegate = new SimpleCompiledExportDelegate(delegateInfo, this); activationDelegate = compiledExportDelegate.CompileDelegate(); dependsOn = compiledExportDelegate.Dependencies; delegateDictionary[_exportType] = new Tuple<ExportActivationDelegate, List<ExportStrategyDependency>>(activationDelegate, compiledExportDelegate.Dependencies); } else { activationDelegate = activationInfo.Item1; dependsOn = activationInfo.Item2; } }
public virtual void Initialize() { FuncCompiledExportDelegate exportDelegate = new FuncCompiledExportDelegate(delegateInfo, (scope, context) => context.Locate(CONTEXT_KEY),null, null); activationDelegate = exportDelegate.CompileDelegate(); }