/// <inheriteddoc /> protected override object OnGetInstance(Type serviceType, object key) { object result = null; InstanceProvider provider; if (this._SINGLE_PROVIDERS.TryGetValue(serviceType, out provider)) { result = provider.Invoke <object>(this.BaseLocator, key); if (result == null) { throw new ServiceActivationException(serviceType, key); } } bool tryFallback = true; if (result == null) { if (this._BASE_LOCATOR != null) { // use base service locator instead tryFallback = false; result = this._BASE_LOCATOR .GetInstance(serviceType, key); } } if (tryFallback) { // try by fallback, if defined SingleInstanceFallbackProvider fb = this.SingleInstanceFallback; if (fb != null) { result = fb(this, key, serviceType); } } return(result); }
/// /// <summary> /// Initializes a new instance of the <see cref="DelegateServiceLocator" /> class. /// </summary> /// <param name="baseLocator">The value for <see cref="DelegateServiceLocator.BaseLocator" /> property.</param> /// <param name="multiFallback">The value for <see cref="DelegateServiceLocator.MultiInstanceFallback" /> property.</param> /// <param name="singleFallback">The value for <see cref="DelegateServiceLocator.SingleInstanceFallback" /> property.</param> /// <param name="syncRoot">The value for the <see cref="ServiceLocatorBase._SYNC_ROOT" /> field.</param> public DelegateServiceLocator(IServiceLocator baseLocator = null, MultiInstanceFallbackProvider multiFallback = null, SingleInstanceFallbackProvider singleFallback = null, object syncRoot = null) : base(syncRoot: syncRoot) { this.BaseLocator = baseLocator; this.MultiInstanceFallback = multiFallback; this.SingleInstanceFallback = singleFallback; }