private void ApplySettings(ModularServiceSettingsList <TService> settingsList, string text) { Queue <ServiceCallInfo <TService> > newConstructors = new Queue <ServiceCallInfo <TService> >(); for (int i = 0; i < settingsList.Count; i++) { ServiceModuleSettings moduleSettings = settingsList[i]; if (settingsList[i] == null) { try { throw new NullReferenceException($"{nameof(moduleSettings)} at index {i} is null."); } catch (Exception e) { switch (_exceptionHandler.HandleConfigApplyException(e, moduleSettings, i)) { case OnExceptionAction.Throw: throw; case OnExceptionAction.Stop: _constructors = newConstructors; return; case OnExceptionAction.Continue: continue; } } } else if (settingsList[i].Ignore) { continue; } try { string assemblyPath = moduleSettings.PathType == PathType.Absolute ? moduleSettings.DllPath : Path.Combine(_configuration.GetValue <string>(WebHostDefaults.ContentRootKey), moduleSettings.DllPath); Type moduleType = TypeHelper.LoadModuleTypeFromAssembly(assemblyPath, moduleSettings.FullNameOfType, typeof(IModule <TService>)); ServiceCallInfo <TService> callInfo = new ServiceCallInfo <TService> { Constructor = Expression.Lambda <Func <IModule <TService> > >(Expression.New(moduleType)).Compile(), OnConstructorExceptionAction = settingsList[i].OnConstructorExceptionAction, OnInitializeExceptionAction = settingsList[i].OnInitializeExceptionAction }; newConstructors.Enqueue(callInfo); } catch (Exception e) { switch (moduleSettings.OnConfigApplyExceptionAction ?? _exceptionHandler.HandleConfigApplyException(e, moduleSettings, i)) { case OnExceptionAction.Throw: throw; case OnExceptionAction.Stop: _constructors = newConstructors; return; case OnExceptionAction.Continue: continue; } } } _constructors = newConstructors; }
public OnExceptionAction HandleConfigApplyException(Exception e, ServiceModuleSettings settings, int configIndex) => OnExceptionAction.Throw;