/// <summary> /// init, must called to setup windsor container /// </summary> public void Init(Action action, bool enablePlugins) { if (!gate.TryEnter()) { return; } try { _container = new ServiceContainer(); if (action != null) { action.Invoke(); } _container.ComponentCreated += _container_ComponentCreated; if (enablePlugins) { PluginBootstrapper pluginBootstrapper = PluginBootstrapper.Instance; pluginBootstrapper.InitializePlugins(pluginBootstrapper.GetPluginDefinitions()); } } catch (Exception ex) { throw new KissException("ServiceLocator init failed!", ex); } }
public void Plugin_WithoutInitializerDefinition_IsNotInvoked() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(PlugIn3) }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); Assert.That(PlugIn3.WasInitialized, Is.False); }
public void AutoInitializePlugin_IsInvoked() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(PlugIn2) }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); Assert.That(PlugIn2.WasInitialized, Is.True); }
public void Plugins_CanBeInitialized_FromConfiguration() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(typeof(PlugIn1).Assembly, new[] { typeof(PlugIn3) }); EngineSection config = CreateConfiguration(new[] { new PluginInitializerElement { Name = "ignored", Type = typeof(PlugIn3).AssemblyQualifiedName } }, null); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder, config); invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); Assert.That(PlugIn3.WasInitialized, Is.True); }
public void AutoInitialized_PluginInitializers_CanBeRemoved_UsingConfiguration_ByType() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(typeof(PlugIn1).Assembly, new[] { typeof(PlugIn2) }); EngineSection config = CreateConfiguration(null, new[] { new PluginInitializerElement { Name = "ignored", Type = typeof(PlugIn2).AssemblyQualifiedName } }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder, config); invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); Assert.That(PlugIn2.WasInitialized, Is.False); }
public void Initializers_AreExecuted_AfterException() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; ThrowingPlugin1.Throw = true; PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate { invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); }); ThrowingPlugin1.Throw = false; Assert.That(PlugIn2.WasInitialized, Is.True); }
public void InnerException_IsInnerException_OfInitializationException() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) }); mocks.ReplayAll(); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; ThrowingPlugin1.Throw = true; PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate { invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); }); ThrowingPlugin1.Throw = false; Assert.That(ex.InnerException, Is.TypeOf(typeof(SomeException))); Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy.")); }
public void InnerExceptions_AreAdded_ToInitializationException() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2), typeof(ThrowingPlugin2) }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; ThrowingPlugin1.Throw = true; ThrowingPlugin2.Throw = true; PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate { invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); }); ThrowingPlugin1.Throw = false; ThrowingPlugin2.Throw = false; Assert.That(ex.InnerExceptions.Length, Is.EqualTo(2)); Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy.")); Assert.That(ex.Message.Contains("ThrowingPlugin2 is really mad.")); }