public SharedModel(IPostable parentForm, IExportStrategy exportStrategy) { Utils.CheckNotNull(parentForm, "parentForm"); Utils.CheckNotNull(exportStrategy, "exportStrategy"); m_ParentForm = parentForm; ExportStrategy = exportStrategy; }
/// <summary> /// Exports the objects loaded into this transporter (including their contents) in a custom format for transport to another system. /// At the target system, the data can be loaded via <see cref="LoadTransportData(Stream,IImportStrategy)"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> to which to export the loaded objects.</param> /// <param name="strategy">The strategy to be used for exporting data. This must match the strategy used with /// <see cref="LoadTransportData(System.IO.Stream,Remotion.Data.DomainObjects.DomainImplementation.Transport.IImportStrategy)"/>.</param> public void Export(Stream stream, IExportStrategy strategy) { IEnumerable <DataContainer> transportedContainers = GetTransportedContainers(); TransportItem[] transportItems = TransportItem.PackageDataContainers(transportedContainers).ToArray(); strategy.Export(stream, transportItems); }
/// <summary> /// Internal filter method that loops through the collection of filters /// </summary> /// <param name="context">injection context</param> /// <param name="strategy">export strategy</param> /// <returns>true if the strategy matches</returns> private bool InternalExportStrategyFilter(IInjectionContext context, IExportStrategy strategy) { if (UseOr) { foreach (ExportStrategyFilter exportStrategyFilter in filters) { if (exportStrategyFilter(context, strategy)) { return true; } } return false; } foreach (ExportStrategyFilter exportStrategyFilter in filters) { if (!exportStrategyFilter(context, strategy)) { return false; } } return true; }
/// <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; }
/// <summary> /// Condition meet /// </summary> /// <param name="scope">injection scope</param> /// <param name="injectionContext">injection context</param> /// <param name="exportStrategy">export strategy</param> /// <returns>condition</returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { bool found = false; CurrentInjectionInfo[] injectionStack = injectionContext.GetInjectionStack(); for (int i = injectionStack.Length - 1; i >= 0 && !found; i--) { CurrentInjectionInfo injectionInfo = injectionStack[i]; foreach (Type ancestorType in ancestorTypes) { if (ancestorType.GetTypeInfo().IsInterface) { if(injectionInfo.ActivationType == ancestorType || (injectionInfo.CurrentExportStrategy != null && injectionInfo.CurrentExportStrategy.ExportTypes.Contains(ancestorType))) { found = true; break; } } else if (injectionInfo.ActivationType == ancestorType) { found = true; break; } } } return found; }
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; }
public void Inspect(IExportStrategy exportStrategy) { exportStrategy.EnrichWithDelegate((scope, context, instance) => { PageFactory.InitElements(_webDriver,instance); return instance; }); }
/// <summary> /// Default constructor /// </summary> /// <param name="property"></param> /// <param name="targetStrategy"></param> /// <param name="exportCondition"></param> public PropertyExportStrategy(PropertyInfo property, IExportStrategy targetStrategy, IExportCondition exportCondition) : base(property.PropertyType) { this.propertyInfo = property; this.strategy = targetStrategy; this.exportCondition = exportCondition; }
/// <summary> /// Inspect strategies /// </summary> /// <param name="exportStrategy">strategy</param> public void Inspect(IExportStrategy exportStrategy) { IConfigurableExportStrategy configurableExport = exportStrategy as IConfigurableExportStrategy; if (configurableExport != null && _typesThatFunc(exportStrategy.ActivationType)) { configurableExport.SetPriority(_priority); } }
/// <summary> /// Called to determine if the export strategy meets the condition to be activated /// </summary> /// <param name="scope">injection scope that this export exists in</param> /// <param name="injectionContext">injection context for this request</param> /// <param name="exportStrategy">export strategy being tested</param> /// <returns>true if the export meets the condition</returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { foreach (IExportCondition exportCondition in exportConditions) { if (!exportCondition.ConditionMeet(scope, injectionContext, exportStrategy)) { return false; } } return true; }
/// <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); }
public TypeDefinitionMapper( ICommentsProvider commentsProvider, ITypeDefinitionNameMapper typeDefinitionNameMapper, ILiteralTypeMapper literalTypeMapper, IEnumFieldsProvider enumFieldsProvider, IExportStrategy exportStrategy ) { _commentsProvider = commentsProvider; _literalTypeMapper = literalTypeMapper; _enumFieldsProvider = enumFieldsProvider; _exportStrategy = exportStrategy; _typeDefinitionNameMapper = typeDefinitionNameMapper; }
/// <summary> /// Called to determine if the export strategy meets the condition to be activated /// </summary> /// <param name="scope">injection scope that this export exists in</param> /// <param name="injectionContext">injection context for this request</param> /// <param name="exportStrategy">export strategy being tested</param> /// <returns>true if the export meets the condition</returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (injectionContext.TargetInfo != null) { foreach (Attribute injectionTypeAttribute in injectionContext.TargetInfo.InjectionTypeAttributes) { if (injectionTypeAttribute.GetType().GetTypeInfo().IsAssignableFrom(attributeType.GetTypeInfo())) { return true; } } } return false; }
/// <summary> /// Called to determine if the export strategy meets the condition to be activated /// </summary> /// <param name="scope">injection scope that this export exists in</param> /// <param name="injectionContext">injection context for this request</param> /// <param name="exportStrategy">export strategy being tested</param> /// <returns>true if the export meets the condition</returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (answer.HasValue) { return answer.Value; } bool returnValue = ConfigurationManager.AppSettings[settingName] == null; if (cacheAnswer) { answer = returnValue; } return returnValue; }
/// <summary> /// returns true when the app.config setting is equal to the provided value /// </summary> /// <param name="scope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (answer.HasValue) { return answer.Value; } string appSetting = ConfigurationManager.AppSettings[settingName]; bool returnValue = false; if (appSetting != null) { if (settingValue == null) { return false; } if (appSetting.GetType() == settingValue.GetType()) { returnValue = Equals(settingValue, appSetting); } try { returnValue = Equals(settingValue, Convert.ChangeType(appSetting, settingValue.GetType())); } catch (Exception exp) { Logger.Error( string.Format("Exception thrown while converting {0} to {1}", appSetting, settingValue.GetType().FullName), supplemental, exp); } } else if (settingValue == null) { returnValue = true; } if (cacheAnswer) { answer = returnValue; } return returnValue; }
/// <summary> /// Called to determine if the export strategy meets the condition to be activated /// </summary> /// <param name="scope">injection scope that this export exists in</param> /// <param name="injectionContext">injection context for this request</param> /// <param name="exportStrategy">export strategy being tested</param> /// <returns>true if the export meets the condition</returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { IInjectionTargetInfo targetInfo = injectionContext.TargetInfo; if (targetInfo != null && injectedType != null) { foreach (Type type in injectedType) { if (targetInfo.InjectionType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) { return true; } } } return false; }
/// <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; }
public DefaultInterfaceMapper( ICommentsProvider commentsProvider, IInterfaceNameMapper interfaceNameMapper, IInterfacePropertyMapper interfacePropertyMapper, IExpendTypesProvider expendTypesProvider, IExportStrategy exportStrategy, ITypeReferenceMapper typeReferenceMapper, IInterfacePropertiesProvider interfacePropertiesProvider ) { _interfacePropertyMapper = interfacePropertyMapper; _expendTypesProvider = expendTypesProvider; _exportStrategy = exportStrategy; _typeReferenceMapper = typeReferenceMapper; _interfacePropertiesProvider = interfacePropertiesProvider; _commentsProvider = commentsProvider; _interfaceNameMapper = interfaceNameMapper; }
public string Export(string fileName, string exportType) { // get data... IExportStrategy exporter = null; switch (exportType) { case "excel": exporter = new ExcelExporter(); break; case "pdf": default: exporter = new PDFExporter(); break; } return(exporter.Export(fileName)); }
/// <summary> /// Called to determine if the export strategy meets the condition to be activated /// </summary> /// <param name="scope">injection scope that this export exists in</param> /// <param name="injectionContext">injection context for this request</param> /// <param name="exportStrategy">export strategy being tested</param> /// <returns>true if the export meets the condition</returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { if (answer.HasValue) { return answer.Value; } string appSetting = ConfigurationManager.AppSettings[settingName]; bool returnValue = string.IsNullOrEmpty(appSetting) || string.Compare("false", appSetting, StringComparison.CurrentCultureIgnoreCase) == 0; if (cacheAnswer) { answer = 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="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> /// increases the strategies priority based on the number of closed parameters it has /// </summary> /// <param name="exportStrategy"></param> public void Inspect(IExportStrategy exportStrategy) { IConfigurableExportStrategy configurableExport = exportStrategy as IConfigurableExportStrategy; if (configurableExport != null && exportStrategy.ActivationType.GetTypeInfo().IsGenericTypeDefinition) { int maxClosed = 0; int openGenericParams = exportStrategy.ActivationType.GetTypeInfo().GenericTypeParameters.Length; foreach (Type exportType in exportStrategy.ExportTypes) { int exportTypeParamCount = exportType.GetTypeInfo().GenericTypeParameters.Length; int numClosed = exportTypeParamCount - openGenericParams; if (numClosed > maxClosed) { maxClosed = numClosed; } } configurableExport.SetPriority(configurableExport.Priority + maxClosed); } }
/// <summary> /// Creates a new <see cref="FileExport"/>. /// </summary> /// <param name="createDataReaderPool"> /// The factory method for creating an <see cref="IDataReaderPool"/> to /// pass to the export strategies /// </param> /// <param name="createSubProgressReporter">The factory method for creating a sub-progress reporter</param> /// <param name="dataBlockScanner">The data block scanner</param> /// <param name="saveAsSingleFile">The strategy for saving a single input file</param> /// <param name="saveAsContiguousFile">The strategy for saving multiple results as a single file</param> /// <param name="saveAsSeparateFiles">The strategy for saving multiple results as separate files</param> /// <param name="exportToXml">The strategy for exporting results to an XML document</param> public FileExport(Creator <IDataReaderPool> createDataReaderPool, Creator <IProgressReporter, IProgressReporter, long, long, long> createSubProgressReporter, DataBlockScanner dataBlockScanner, IExportStrategy <IInputFile> saveAsSingleFile, IExportStrategy <IDataPacket> saveAsContiguousFile, IExportStrategy <IEnumerable <object> > saveAsSeparateFiles, ExportToXml exportToXml) { PreConditions.Argument("createDataReaderPool").Value(createDataReaderPool).IsNotNull(); PreConditions.Argument("createSubProgressReporter").Value(createSubProgressReporter).IsNotNull(); PreConditions.Argument("dataBlockScanner").Value(dataBlockScanner).IsNotNull(); PreConditions.Argument("saveAsSingleFile").Value(saveAsSingleFile).IsNotNull(); PreConditions.Argument("saveAsContiguousFile").Value(saveAsContiguousFile).IsNotNull(); PreConditions.Argument("saveAsSeparateFiles").Value(saveAsSeparateFiles).IsNotNull(); PreConditions.Argument("exportToXml").Value(exportToXml).IsNotNull(); _createDataReaderPool = createDataReaderPool; _createSubProgressReporter = createSubProgressReporter; _dataBlockScanner = dataBlockScanner; _saveAsSingleFile = saveAsSingleFile; _saveAsContiguousFile = saveAsContiguousFile; _saveAsSeparateFiles = saveAsSeparateFiles; _exportToXml = exportToXml; }
public void Inspect(IExportStrategy exportStrategy) { CompiledExportStrategy compiledExportStrategy = exportStrategy as CompiledExportStrategy; if (compiledExportStrategy != null) { foreach (PropertyInfo declaredProperty in exportStrategy.ActivationType.GetRuntimeProperties()) { if (!declaredProperty.CanWrite || declaredProperty.SetMethod.IsStatic || !ReflectionService.CheckTypeIsBasedOnAnotherType(declaredProperty.PropertyType, _propertyType)) { continue; } if (!string.IsNullOrEmpty(_propertyName) && string.Compare(_propertyName,declaredProperty.Name,StringComparison.CurrentCultureIgnoreCase) != 0) { continue; } if (_propertyPicker != null && !_propertyPicker(declaredProperty)) { continue; } compiledExportStrategy.ImportProperty(new ImportPropertyInfo { AfterConstruction = _afterConstructor, Property = declaredProperty, ValueProvider = _valueProvider }); } } }
public void StrategyInitializing(IExportStrategy exportStrategy) { CompiledExportStrategy compiledExportStrategy = exportStrategy as CompiledExportStrategy; if (compiledExportStrategy != null) { foreach (PropertyInfo declaredProperty in exportStrategy.ActivationType.GetTypeInfo().DeclaredProperties) { if (!declaredProperty.CanWrite || declaredProperty.SetMethod.IsStatic || !ReflectionService.CheckTypeIsBasedOnAnotherType(declaredProperty.PropertyType, _propertyType)) { continue; } if (!string.IsNullOrEmpty(_propertyName) && _propertyName != declaredProperty.Name) { continue; } if (_propertyPicker != null && !_propertyPicker(declaredProperty)) { continue; } compiledExportStrategy.ImportProperty(new ImportPropertyInfo { AfterConstruction = _afterConstructor, Property = declaredProperty, ValueProvider = _valueProvider }); } } }
public void GivenExportTypeTest() { var exportType = "excel"; // 完整重構的 strategy // 在報表物件內部已不再包含策略的選擇(switch),變成需由外部決定後再傳入報表物件 IExportStrategy exporter = null; switch (exportType) { case "pdf": exporter = new PDFExporter(); break; case "excel": default: exporter = new ExcelExporter(); break; } var reportObj = new LunchReport_V3(exporter); var result = reportObj.Export("午餐清單"); Assert.AreEqual(exportType, _GetFileExt(result)); }
public Forest() { _trees = new List <Tree.Tree>(); _exportStrategy = new ExportToJson(); _splitter = new SplitterRss(); }
public void Add(IExportStrategy strategy) { strategies.Add(strategy); }
public ReportExporter(IExportStrategy strategy) { this.ExportStrategy = strategy; }
public LunchReport_V3(IExportStrategy exporter) { _exporter = exporter; }
public void SetFormat(Constants.FORMATS_AVALIBLES format) { logger.Info("Export {0}", format); _ExporterStrategy = _ExporterStrategies[format]; }
public SimpleCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, IExportStrategy exportStrategy) : base(exportDelegateInfo, exportStrategy,null) { }
public FinancialReport(IExportStrategy exportStrategy) { _exportStrategy = 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) { if (instance == null) { lock (lockObject) { if (instance == null) { instance = CreateInSingletonScope(creationDelegate, exportStrategy.OwningScope, injectionContext); } } } return instance; }
/// <summary> /// Default Constructor /// </summary> /// <param name="exportDelegateInfo"></param> /// <param name="exportStrategy"></param> /// <param name="owningScope"></param> public InstanceCompiledExportDelegate(CompiledExportDelegateInfo exportDelegateInfo, IExportStrategy exportStrategy, IInjectionScope owningScope) : base(exportDelegateInfo, exportStrategy, owningScope) { }
private TransportedDomainObjects ExportAndLoadTransportData(IImportStrategy importStrategy, IExportStrategy exportStrategy) { _transporter.Export(_stream, exportStrategy); _stream.Seek(0, SeekOrigin.Begin); return(DomainObjectTransporter.LoadTransportData(_stream, importStrategy)); }
/// <summary> /// Returns true only when there is no debugger attached /// </summary> /// <param name="scope"></param> /// <param name="injectionContext"></param> /// <param name="exportStrategy"></param> /// <returns></returns> public bool ConditionMeet(IInjectionScope scope, IInjectionContext injectionContext, IExportStrategy exportStrategy) { return !Debugger.IsAttached; }
/// <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> /// Initializes a new instance of the <see cref="ProfileExporter"/> class. /// </summary> /// <param name="exportStrategy">The strategy to use when exporting profiles</param> public ProfileExporter(IExportStrategy exportStrategy) { this.exportStrategy = exportStrategy; }
/// <summary> /// Adds a secondary export strategy to this strategy /// </summary> /// <param name="strategy">export strategy</param> protected void AddSecondaryExport(IExportStrategy strategy) { _secondaryExports = _secondaryExports.Add(strategy); }