Skip to content

Commit 0e42e40

Browse files
authored
Merge pull request #3471 from MDoerner/PortToCastleWindsor
Ported DI/IoC over to Castle Windsor. Farewell Ninject!
2 parents 6759c49 + cd64320 commit 0e42e40

27 files changed

+1118
-722
lines changed

RetailCoder.VBE/Extension.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using Extensibility;
2-
using Ninject;
3-
using Ninject.Extensions.Factory;
4-
using Rubberduck.Root;
52
using Rubberduck.UI;
63
using System;
74
using System.ComponentModel;
@@ -13,9 +10,10 @@
1310
using System.Runtime.InteropServices;
1411
using System.Windows.Forms;
1512
using System.Windows.Threading;
13+
using Castle.Windsor;
1614
using Microsoft.Vbe.Interop;
17-
using Ninject.Extensions.Interception;
1815
using NLog;
16+
using Rubberduck.Root;
1917
using Rubberduck.Settings;
2018
using Rubberduck.SettingsProvider;
2119
using Rubberduck.VBEditor.Events;
@@ -41,7 +39,9 @@ public class _Extension : IDTExtensibility2
4139
private bool _isInitialized;
4240
private bool _isBeginShutdownExecuted;
4341

44-
private IKernel _kernel;
42+
private GeneralSettings _initialSettings;
43+
44+
private IWindsorContainer _container;
4545
private App _app;
4646
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
4747

@@ -152,12 +152,12 @@ private void InitializeAddIn()
152152
};
153153
var configProvider = new GeneralConfigProvider(configLoader);
154154

155-
var settings = configProvider.Create();
156-
if (settings != null)
155+
_initialSettings = configProvider.Create();
156+
if (_initialSettings != null)
157157
{
158158
try
159159
{
160-
var cultureInfo = CultureInfo.GetCultureInfo(settings.Language.Code);
160+
var cultureInfo = CultureInfo.GetCultureInfo(_initialSettings.Language.Code);
161161
Dispatcher.CurrentDispatcher.Thread.CurrentUICulture = cultureInfo;
162162
}
163163
catch (CultureNotFoundException)
@@ -170,7 +170,7 @@ private void InitializeAddIn()
170170
}
171171

172172
Splash splash = null;
173-
if (settings.ShowSplash)
173+
if (_initialSettings.ShowSplash)
174174
{
175175
splash = new Splash
176176
{
@@ -210,10 +210,9 @@ private void Startup()
210210
currentDomain.UnhandledException += HandlAppDomainException;
211211
currentDomain.AssemblyResolve += LoadFromSameFolder;
212212

213-
_kernel = new StandardKernel(new NinjectSettings {LoadExtensions = true}, new FuncModule(), new DynamicProxyModule());
214-
_kernel.Load(new RubberduckModule(_ide, _addin));
215-
216-
_app = _kernel.Get<App>();
213+
_container = new WindsorContainer().Install(new RubberduckIoCInstaller(_ide, _addin, _initialSettings));
214+
215+
_app = _container.Resolve<App>();
217216
_app.Startup();
218217

219218
_isInitialized = true;
@@ -253,11 +252,11 @@ private void ShutdownAddIn()
253252
_app = null;
254253
}
255254

256-
if (_kernel != null)
255+
if (_container != null)
257256
{
258257
_logger.Log(LogLevel.Trace, "Disposing IoC container...");
259-
_kernel.Dispose();
260-
_kernel = null;
258+
_container.Dispose();
259+
_container = null;
261260
}
262261

263262
_isInitialized = false;

0 commit comments

Comments
 (0)