public void Load(ISpeedDateStartable startable, IConfigProvider configProvider, Action <SpeedDateConfig> startedCallback) { _logger = LogManager.GetLogger("SpeedDate"); _config = configProvider.Result; _container = CreateContainer(startable); configProvider.Configure(_container.ResolveAll <IConfig>()); _container.BuildUp(startable); //Filter plugins for namespace & inject configuration into valid plugins foreach (var plugin in _container.ResolveAll <IPlugin>()) { if (_config.Plugins.Namespaces.Split(';').Any(ns => Regex.IsMatch(plugin.GetType().Namespace, ns.Trim().AsRegular()))) { _logger.Debug($"Loading plugin: {plugin}"); //Inject configs, cannot use _container.BuildUp because the configProvider may have additional IConfigs var fields = from field in plugin.GetType() .GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public) where Attribute.IsDefined(field, typeof(InjectAttribute)) select field; foreach (var field in fields) { if (field.GetValue(plugin) == null && _config.TryGetConfig(field.FieldType.FullName, out var config)) { field.SetValue(plugin, config); } } } else { _container.Unregister(typeof(IPlugin), plugin.GetType().FullName); } } //Inject additional dependencies e.g. ILogger foreach (var plugin in _container.ResolveAll <IPlugin>()) { _container.BuildUp(plugin); } //Finally notify every plugin that loading has finished foreach (var plugin in _container.ResolveAll <IPlugin>()) { plugin.Loaded(); _logger.Info($"Loaded {plugin.GetType().Name}"); } startedCallback.Invoke(_config); }
public T TryResolve <T> () where T : class { if (!mContainer.TryResolve <T>(out T instance)) { instance = default; } else { mContainer.BuildUp(instance); } return(instance); }
public void StartEventSource(IEventSource source) { _container.BuildUp(source); _eventSources.Add(source); source.LoadConfig(_container.Resolve <IPluginConfig>()); source.Start(); EventSourceRegistered?.Invoke(null, new EventSourceRegisteredEventArgs(source)); }
public T Resolve <T>() where T : class { var instance = container.Resolve <T>(new ResolveOptions { UnregisteredResolutionAction = UnregisteredResolutionActions.Fail }); if (instance != null) { container.BuildUp(instance, new ResolveOptions { PropertyFilter = HandleAutowiredType, UnregisteredResolutionAction = UnregisteredResolutionActions.Fail }); } return(instance); }
/// <summary> /// Builds up the dependencies of the provided <see cref="UIKit.UIViewController"/> instance. /// </summary> /// <param name="viewController">Instance of <see cref="UIKit.UIViewController"/> to build up.</param> public void BuildUp(UIViewController viewController) { _container.BuildUp(viewController); }