public PropertyMetadataBuilder <T, TProperty> ReturnsService(string key, ServiceSearchMode searchMode = default(ServiceSearchMode)) { return(AddOrReplaceAttribute(new ServicePropertyAttribute() { SearchMode = searchMode, Key = key })); }
protected override T GetServiceCore <T>(string key, ServiceSearchMode searchMode, out bool serviceHasKey) { object res = base.GetServiceCore <T>(key, searchMode, out serviceHasKey); if (res != null) { return((T)res); } var appResources = GetApplicationResources(); if (appResources != null) { if (string.IsNullOrEmpty(key)) { res = appResources.Values.OfType <T>().FirstOrDefault(); } else { var resKey = appResources.Keys.OfType <object>().FirstOrDefault(x => x.Equals(key)); if (resKey != null) { res = appResources[resKey]; } else { res = appResources.Values.OfType <T>().FirstOrDefault(); } } serviceHasKey = true; } return((T)res); }
ServiceInfo FindService <T>(string key, ServiceSearchMode searchMode) where T : class { bool findServiceWithKey = !string.IsNullOrEmpty(key); if (searchMode == ServiceSearchMode.LocalOnly || ParentServiceContainer == null) { return(GetLocalService <T>(findServiceWithKey, key)); } ServiceInfo parent = GetParentService <T>(key, searchMode); if (searchMode == ServiceSearchMode.PreferParents && parent != null && (findServiceWithKey || !parent.HasKey)) { return(parent); } ServiceInfo local = GetLocalService <T>(findServiceWithKey, key); if (local == null) { return(parent); } if (parent == null) { return(local); } return(searchMode == ServiceSearchMode.PreferParents || local.YieldToParent ? FindServiceCore(findServiceWithKey, parent, local) : FindServiceCore(findServiceWithKey, local, parent)); }
ServiceInfo GetParentService <T>(string key, ServiceSearchMode searchMode) where T : class { bool serviceHasKey; T service = ParentServiceContainer.GetService <T>(key, searchMode, out serviceHasKey); return(service == null ? null : new ServiceInfo(serviceHasKey, service, false)); }
public T GetService <T>(string key, ServiceSearchMode searchMode = ServiceSearchMode.PreferLocal) where T : class { bool serviceHasKey; IServiceContainer serviceCOntainer = this; return(serviceCOntainer.GetService <T>(key, searchMode, out serviceHasKey)); }
public AreaAnalystConfiguration(string routeFilePathName, GeoCollection <object> parameters) { this.MapUnit = GeographyUnit.Meter; this.routeFilePathName = routeFilePathName; this.DistanceUnit = DistanceUnit.Mile; if (parameters.Contains("category")) { this.category = parameters["category"].ToString(); } if (parameters.Contains("subCategory")) { this.subCategory = parameters["subCategory"].ToString().Replace(">~", ">="); } if (parameters.Contains("searchPoint")) { this.searchPoint = PointShape.CreateShapeFromWellKnownData(parameters["searchPoint"].ToString()) as PointShape; } if (parameters.Contains("searchMode") && parameters["searchMode"].ToString().Equals("ServiceArea", StringComparison.OrdinalIgnoreCase)) { this.serviceSearchMode = ServiceSearchMode.ServiceArea; this.drivingTime = Convert.ToInt32(parameters["driveTime"].ToString(), CultureInfo.InvariantCulture); } else { this.serviceSearchMode = ServiceSearchMode.BufferArea; this.bufferDistance = Convert.ToDouble(parameters["bufferDistance"].ToString(), CultureInfo.InvariantCulture); this.distanceUnit = GetDistanceFrom(parameters["distanceUnit"].ToString()); } }
ServiceInfo FindService <T>(string key, ServiceSearchMode searchMode) where T : class { if (searchInParentServiceInProgress) { throw new Exception("A ServiceContainer should not be a direct or indirect parent for itself."); } bool findServiceWithKey = !string.IsNullOrEmpty(key); if (searchMode == ServiceSearchMode.LocalOnly || ParentServiceContainer == null) { return(GetLocalService <T>(findServiceWithKey, key)); } ServiceInfo parent = GetParentService <T>(key, searchMode); if (searchMode == ServiceSearchMode.PreferParents && parent != null && (findServiceWithKey || !parent.HasKey)) { return(parent); } ServiceInfo local = GetLocalService <T>(findServiceWithKey, key); if (local == null) { return(parent); } if (parent == null) { return(local); } return(searchMode == ServiceSearchMode.PreferParents || local.YieldToParent ? FindServiceCore(findServiceWithKey, parent, local) : FindServiceCore(findServiceWithKey, local, parent)); }
ServiceInfo GetParentService <T>(string key, ServiceSearchMode searchMode) where T : class { searchInParentServiceInProgress = true; try { return(ServiceInfo.Create <T>(ParentServiceContainer, key, searchMode)); } finally { searchInParentServiceInProgress = false; } }
protected virtual T GetServiceCore <T>(string key, ServiceSearchMode searchMode, out bool serviceHasKey) where T : class { CheckServiceType <T>(); ServiceInfo serviceInfo = FindService <T>(key, searchMode); if (serviceInfo == null) { serviceHasKey = false; return(null); } serviceHasKey = serviceInfo.HasKey; return((T)serviceInfo.Service); }
T IServiceContainer.GetService <T>(string key, ServiceSearchMode searchMode, out bool serviceHasKey) { CheckServiceType <T>(); ServiceInfo serviceInfo = FindService <T>(key, searchMode); if (serviceInfo == null) { serviceHasKey = false; return(null); } serviceHasKey = serviceInfo.HasKey; return((T)serviceInfo.Service); }
protected virtual object GetServiceCore(Type type, string key, ServiceSearchMode searchMode, out bool serviceHasKey) { CheckServiceType(type); ServiceInfo serviceInfo = FindService(type, key, searchMode); if (serviceInfo == null) { serviceHasKey = false; return(null); } serviceHasKey = serviceInfo.HasKey; return(serviceInfo.Service); }
protected override object GetServiceCore(Type type, string key, ServiceSearchMode searchMode, out bool serviceHasKey) { object res = base.GetServiceCore(type, key, searchMode, out serviceHasKey); if (res != null) { return(res); } var appResources = GetApplicationResources(type); if (!string.IsNullOrEmpty(key) && appResources.ContainsKey(key)) { return(appResources[key]); } serviceHasKey = true; return(appResources.FirstOrDefault().Value); }
ServiceInfo FindService(Type t, string key, ServiceSearchMode searchMode) { bool findServiceWithKey = !string.IsNullOrEmpty(key); if (searchMode == ServiceSearchMode.LocalOnly || ParentServiceContainer == null) { return(GetLocalService(t, findServiceWithKey, key)); } ServiceInfo parent; try { if (searchInParentServiceLocker) { throw new Exception("A ServiceContainer should not be a direct or indirect parent for itself."); } searchInParentServiceLocker = true; parent = ServiceInfo.Create(ParentServiceContainer, t, key, searchMode); } finally { searchInParentServiceLocker = false; } if (searchMode == ServiceSearchMode.PreferParents && parent != null && (findServiceWithKey || !parent.HasKey)) { return(parent); } ServiceInfo local = GetLocalService(t, findServiceWithKey, key); if (local == null) { return(parent); } if (parent == null) { return(local); } return(searchMode == ServiceSearchMode.PreferParents || local.YieldToParent ? FindServiceCore(findServiceWithKey, parent, local) : FindServiceCore(findServiceWithKey, local, parent)); }
public static T GetRequiredService <T>(this IServiceContainer serviceContainer, ServiceSearchMode searchMode) where T : class { VerifyServiceContainer(serviceContainer); return(CheckService(serviceContainer.GetService <T>(searchMode))); }
public T GetService <T>(ServiceSearchMode searchMode = ServiceSearchMode.PreferLocal) where T : class { return(this.GetService <T>(null, searchMode)); }
public static ServiceInfo Create(IServiceContainer container, Type t, string key, ServiceSearchMode searchMode) { bool hasKey; var service = container.GetService(t, key, searchMode, out hasKey); if (service == null) { return(null); } return(new ServiceInfo(key, hasKey, service, false)); }
public T GetService <T>(ServiceSearchMode searchMode = ServiceSearchMode.PreferLocal) where T : class { return(((IServiceContainer)this).GetService <T>(searchMode)); }
object IServiceContainer.GetService(Type type, string key, ServiceSearchMode searchMode, out bool serviceHasKey) { return(GetServiceCore(type, key, searchMode, out serviceHasKey)); }
T IServiceContainer.GetService <T>(ServiceSearchMode searchMode) { bool serviceHasKey; return((T)GetServiceCore(typeof(T), null, searchMode, out serviceHasKey)); }
T IServiceContainer.GetService <T>(string key, ServiceSearchMode searchMode) { bool serviceHasKey; return((T)GetServiceCore(typeof(T), key, searchMode, out serviceHasKey)); }
public new T GetService <T>(ServiceSearchMode searchMode = ServiceSearchMode.PreferLocal) where T : class { return(base.GetService <T>(searchMode)); }
public static T GetRequiredService <T>(this IServiceContainer serviceContainer, string key, ServiceSearchMode searchMode = ServiceSearchMode.PreferLocal) where T : class { VerifyServiceContainer(serviceContainer); bool serviceHasKey; var res = (T)serviceContainer.GetService(typeof(T), key, searchMode, out serviceHasKey); return(CheckService(res)); }
public static object GetService(this IServiceContainer serviceContainer, Type type, string key, ServiceSearchMode searchMode = ServiceSearchMode.PreferLocal) { VerifyServiceContainer(serviceContainer); bool serviceHasKey; return(serviceContainer.GetService(type, key, searchMode, out serviceHasKey)); }
public TBuilder ReturnsService(ServiceSearchMode searchMode = default(ServiceSearchMode)) { return(ReturnsService(null, searchMode)); }
public ServicePropertyAttribute(ServiceSearchMode searchMode) : this(true) { this.SearchMode = searchMode; }
T IServiceContainer.GetService <T>(string key, ServiceSearchMode searchMode, out bool serviceHasKey) { return(GetServiceCore <T>(key, searchMode, out serviceHasKey)); }
public PropertyMetadataBuilder <T, TProperty> ReturnsService(ServiceSearchMode searchMode = default(ServiceSearchMode)) { return(ReturnsService(null, searchMode)); }
public static ServiceInfo Create <T>(IServiceContainer container, string key, ServiceSearchMode searchMode) where T : class { bool hasKey; var service = container.GetService <T>(key, searchMode, out hasKey); if (service == null) { return(null); } return(new ServiceInfo(key, hasKey, service, false)); }
protected virtual T GetService <T>(string key, ServiceSearchMode searchMode) where T : class { return(ServiceContainer.GetService <T>(key, searchMode)); }