/// <summary> /// Queues a request to create an IMapper. /// </summary> /// <param name="mapperRequest"></param> /// <returns>The 'true' key present in the dictionary. This will be the key given if no previous matching registration has occured.</returns> public IAutoMapperRequestKeyGen RegisterAutoMapperRequest(IAutoMapperRequestKeyGen mapperRequest) { IAutoMapperRequestKeyGen result; if (_sealedAutoMappers.ContainsKey(mapperRequest)) { //ICollection<IAutoMapperRequestKeyGen> keys = _sealedAutoMappers.Keys; //// TODO: This is relatively resource intensive, perhaps there's a better way. //IAutoMapperRequestKeyGen existingKey = keys.FirstOrDefault(x => x.DestinationTypeGenDef.Equals(autoMapperRequestKeyGen.DestinationTypeGenDef)); //if(!ReferenceEquals(existingKey, autoMapperRequestKeyGen)) //{ // System.Diagnostics.Debug.WriteLine("The mapRequest given to RegisterRawAutoMapperRequest was not the original key."); //} //result = existingKey; result = mapperRequest; } else { _unSealedAutoMappers.GetOrAdd(mapperRequest); result = mapperRequest; } return(result); }
public IMapper GetAutoMapper(IAutoMapperRequestKeyGen mapperRequest) { IAutoMapperRequestKeyGen save = mapperRequest; if (_sealedAutoMappers.TryGetValue(mapperRequest, out IMapper result)) { CheckForChanges(save, mapperRequest, "Find in Sealed -- First Check."); return(result); } _unSealedAutoMappers.GetOrAdd(mapperRequest); CheckForChanges(save, mapperRequest, "GetOrAdd to UnSealed"); // Seal all pending mapper requests. int numberInThisBatch = SealThis(pCntr++); CheckForChanges(save, mapperRequest, "Seal"); if (!_sealedAutoMappers.TryGetValue(mapperRequest, out result)) { CheckForChanges(save, mapperRequest, "Find in Sealed -- second check."); result = null; } return(result); }
// Typed Submit Raw Auto public IAutoMapperRequestKey <TSource, TDestination> SubmitRawAutoMapperRequest <TSource, TDestination> ( IMapTypeDefinition srcMapTypeDef, IMapTypeDefinition dstMapTypeDef, IAutoMapperConfigDetails configuationDetails, IConfigureAMapper <TSource, TDestination> mappingConfiguration, IHaveAMapperConfigurationStep configStarterForThisRequest ) { // Create a MapperBuilder for this request. IAutoMapperBuilder <TSource, TDestination> autoMapperBuilder = BuildTheAutoMapperBuilder <TSource, TDestination>(configStarterForThisRequest); // Create the mapper request. IAutoMapperRequestKey <TSource, TDestination> autoMapperRequestKey = new AutoMapperRequestKey <TSource, TDestination> ( sourceMapTypeDef: srcMapTypeDef, destinationMapTypeDef: dstMapTypeDef, autoMapperConfigDetails: configuationDetails, mappingConfiguration: mappingConfiguration, autoMapperBuilder: autoMapperBuilder); IAutoMapperRequestKeyGen response_AutoMapperRequestKey = RegisterAutoMapperRequest(autoMapperRequestKey); return((IAutoMapperRequestKey <TSource, TDestination>)response_AutoMapperRequestKey); }
private IMapper BuildAutoMapperGen(IAutoMapperRequestKeyGen mapRequestGen) { IAutoMapperRequestKey <TSource, TDestination> mapRequestTyped = mapRequestGen as IAutoMapperRequestKey <TSource, TDestination>; if (mapRequestTyped == null) { throw new InvalidOperationException($"{nameof(mapRequestGen)} does not implement the correct typed {nameof(IAutoMapperRequestKey<TSource, TDestination>)} interface."); } return(BuildAutoMapper(mapRequestTyped)); }
public PropBagMapperRequestKeyGen ( Func <IPropBagMapperRequestKeyGen, ViewModelFactoryInterface, IPropBagMapperGen> mapperCreator, IAutoMapperRequestKeyGen autoMapperRequestKeyGen //, //PropModelType propModel ) { PropBagMapperCreator = mapperCreator; AutoMapperRequestKeyGen = autoMapperRequestKeyGen; //PropModel = propModel; }
private void CheckForChanges(IAutoMapperRequestKeyGen original, IAutoMapperRequestKeyGen current, string operationName) { if (!ReferenceEquals(original, current)) { System.Diagnostics.Debug.WriteLine($"The mapRequest object was replaced by method call: {operationName}."); } if (original != current) { System.Diagnostics.Debug.WriteLine($"The mapRequest was updated by method call: {operationName}."); } }
// From AutoMapperRequestKey (Gen) private IMapper GetRawAutoMapperGen(IAutoMapperRequestKeyGen rawAutoMappeRequestKeyGen) { //if (rawAutoMappeRequestKeyGen.AutoMapper == null) //{ // IMapper autoMapper = _autoMapperService.GetAutoMapper(rawAutoMappeRequestKeyGen); // rawAutoMappeRequestKeyGen.AutoMapper = autoMapper; //} //return rawAutoMappeRequestKeyGen.AutoMapper; IMapper result = _autoMapperService.GetAutoMapper(rawAutoMappeRequestKeyGen); return(result); }
// Gen Submit public IAutoMapperRequestKeyGen SubmitRawAutoMapperRequest ( Type sourceType, Type destinationType, IAutoMapperConfigDetails autoMapperConfigDetails, string configPackageName, IHaveAMapperConfigurationStep configStarterForThisRequest ) { AutoMapperReqSubDelegate mapperRequestSubmitter = GetAutoMapperReqSubDelegate(sourceType, destinationType); IAutoMapperRequestKeyGen result = mapperRequestSubmitter(autoMapperConfigDetails, sourceType, destinationType, configPackageName, configStarterForThisRequest, this); return(result); }
private IAutoMapperRequestKeyGen RequestFactory(IAutoMapperRequestKeyGen key) { return(key); }
private IMapper MapperFactory(IAutoMapperRequestKeyGen key) { IMapper result = key.BuildAutoMapper(); return(result); }
public IMapper GetAutoMapper(IAutoMapperRequestKeyGen autoMapperRequestKey) { return(_autoMapperCache.GetAutoMapper(autoMapperRequestKey)); }
public IAutoMapperRequestKeyGen RegisterAutoMapperRequest(IAutoMapperRequestKeyGen autoMapperRequestKey) { return(_autoMapperCache.RegisterAutoMapperRequest(autoMapperRequestKey)); }