9
9
using Ninject . Modules ;
10
10
using Rubberduck . Common ;
11
11
using Rubberduck . Inspections ;
12
- using Rubberduck . Navigation . CodeExplorer ;
13
12
using Rubberduck . Parsing ;
14
13
using Rubberduck . Parsing . VBA ;
15
14
using Rubberduck . Settings ;
31
30
using Rubberduck . Parsing . Preprocessing ;
32
31
using System . Globalization ;
33
32
using Ninject . Extensions . Interception . Infrastructure . Language ;
33
+ using Ninject . Extensions . NamedScope ;
34
34
using Rubberduck . Parsing . Symbols ;
35
35
using Rubberduck . UI . CodeExplorer . Commands ;
36
36
@@ -76,8 +76,8 @@ public override void Load()
76
76
Assembly . GetAssembly ( typeof ( IIndenter ) )
77
77
} ;
78
78
79
- ApplyConfigurationConvention ( assemblies ) ;
80
79
ApplyDefaultInterfacesConvention ( assemblies ) ;
80
+ ApplyConfigurationConvention ( assemblies ) ;
81
81
ApplyAbstractFactoryConvention ( assemblies ) ;
82
82
83
83
BindCommandsToMenuItems ( ) ;
@@ -96,53 +96,46 @@ public override void Load()
96
96
97
97
Bind < IPresenter > ( ) . To < TestExplorerDockablePresenter > ( )
98
98
. WhenInjectedInto < TestExplorerCommand > ( )
99
- . InSingletonScope ( )
100
- . WithConstructorArgument < IDockableUserControl > ( new TestExplorerWindow { ViewModel = Kernel . Get < TestExplorerViewModel > ( ) } ) ;
99
+ . InSingletonScope ( ) ;
101
100
102
101
Bind < IPresenter > ( ) . To < CodeInspectionsDockablePresenter > ( )
103
102
. WhenInjectedInto < InspectionResultsCommand > ( )
104
- . InSingletonScope ( )
105
- . WithConstructorArgument < IDockableUserControl > ( new CodeInspectionsWindow { ViewModel = Kernel . Get < InspectionResultsViewModel > ( ) } ) ;
103
+ . InSingletonScope ( ) ;
106
104
107
- Bind < IControlView > ( ) . To < ChangesView > ( ) ;
108
- Bind < IControlView > ( ) . To < BranchesView > ( ) ;
109
- Bind < IControlView > ( ) . To < UnsyncedCommitsView > ( ) ;
110
- Bind < IControlView > ( ) . To < SettingsView > ( ) ;
105
+ Bind < IControlView > ( ) . To < ChangesView > ( ) . InCallScope ( ) ;
106
+ Bind < IControlView > ( ) . To < BranchesView > ( ) . InCallScope ( ) ;
107
+ Bind < IControlView > ( ) . To < UnsyncedCommitsView > ( ) . InCallScope ( ) ;
108
+ Bind < IControlView > ( ) . To < SettingsView > ( ) . InCallScope ( ) ;
111
109
112
110
Bind < IControlViewModel > ( ) . To < ChangesViewViewModel > ( )
113
- . WhenInjectedInto < ChangesView > ( ) ;
111
+ . WhenInjectedInto < ChangesView > ( ) . InCallScope ( ) ;
114
112
Bind < IControlViewModel > ( ) . To < BranchesViewViewModel > ( )
115
- . WhenInjectedInto < BranchesView > ( ) ;
113
+ . WhenInjectedInto < BranchesView > ( ) . InCallScope ( ) ;
116
114
Bind < IControlViewModel > ( ) . To < UnsyncedCommitsViewViewModel > ( )
117
- . WhenInjectedInto < UnsyncedCommitsView > ( ) ;
115
+ . WhenInjectedInto < UnsyncedCommitsView > ( ) . InCallScope ( ) ;
118
116
Bind < IControlViewModel > ( ) . To < SettingsViewViewModel > ( )
119
- . WhenInjectedInto < SettingsView > ( ) ;
117
+ . WhenInjectedInto < SettingsView > ( ) . InCallScope ( ) ;
120
118
121
119
Bind < ISourceControlProviderFactory > ( ) . To < SourceControlProviderFactory > ( )
122
120
. WhenInjectedInto < SourceControlViewViewModel > ( ) ;
123
121
124
- Bind < SourceControlDockablePresenter > ( ) . ToSelf ( )
125
- . InSingletonScope ( )
126
- . WithConstructorArgument ( new SourceControlPanel { ViewModel = Kernel . Get < SourceControlViewViewModel > ( ) } ) ;
122
+ Bind < SourceControlDockablePresenter > ( ) . ToSelf ( ) . InSingletonScope ( ) ;
127
123
128
124
BindCommandsToCodeExplorer ( ) ;
129
125
Bind < IPresenter > ( ) . To < CodeExplorerDockablePresenter > ( )
130
126
. WhenInjectedInto < CodeExplorerCommand > ( )
131
- . InSingletonScope ( )
132
- . WithConstructorArgument < IDockableUserControl > ( new CodeExplorerWindow { ViewModel = Kernel . Get < CodeExplorerViewModel > ( ) } ) ;
127
+ . InSingletonScope ( ) ;
133
128
134
129
Bind < IPresenter > ( ) . To < ToDoExplorerDockablePresenter > ( )
135
130
. WhenInjectedInto < ToDoExplorerCommand > ( )
136
- . InSingletonScope ( )
137
- . WithConstructorArgument < IDockableUserControl > ( new ToDoExplorerWindow { ViewModel = Kernel . Get < ToDoExplorerViewModel > ( ) } ) ;
131
+ . InSingletonScope ( ) ;
138
132
139
133
ConfigureRubberduckMenu ( ) ;
140
134
ConfigureCodePaneContextMenu ( ) ;
141
135
ConfigureFormDesignerContextMenu ( ) ;
142
136
ConfigureFormDesignerControlContextMenu ( ) ;
143
137
ConfigureProjectExplorerContextMenu ( ) ;
144
138
145
-
146
139
BindWindowsHooks ( ) ;
147
140
}
148
141
@@ -164,7 +157,7 @@ private void ApplyDefaultInterfacesConvention(IEnumerable<Assembly> assemblies)
164
157
// inspections & factories have their own binding rules
165
158
. Where ( type => ! type . Name . EndsWith ( "Factory" ) && ! type . Name . EndsWith ( "ConfigProvider" ) && ! type . GetInterfaces ( ) . Contains ( typeof ( IInspection ) ) )
166
159
. BindDefaultInterface ( )
167
- . Configure ( binding => binding . InThreadScope ( ) ) ) ; // TransientScope wouldn't dispose disposables
160
+ . Configure ( binding => binding . InCallScope ( ) ) ) ; // TransientScope wouldn't dispose disposables
168
161
}
169
162
170
163
// note: settings namespace classes are injected in singleton scope
@@ -176,24 +169,24 @@ private void ApplyConfigurationConvention(IEnumerable<Assembly> assemblies)
176
169
. BindAllInterfaces ( )
177
170
. Configure ( binding => binding . InSingletonScope ( ) ) ) ;
178
171
179
- Bind < IPersistanceService < CodeInspectionSettings > > ( ) . To < XmlPersistanceService < CodeInspectionSettings > > ( ) . InSingletonScope ( ) ;
180
- Bind < IPersistanceService < GeneralSettings > > ( ) . To < XmlPersistanceService < GeneralSettings > > ( ) . InSingletonScope ( ) ;
181
- Bind < IPersistanceService < HotkeySettings > > ( ) . To < XmlPersistanceService < HotkeySettings > > ( ) . InSingletonScope ( ) ;
182
- Bind < IPersistanceService < ToDoListSettings > > ( ) . To < XmlPersistanceService < ToDoListSettings > > ( ) . InSingletonScope ( ) ;
183
- Bind < IPersistanceService < UnitTestSettings > > ( ) . To < XmlPersistanceService < UnitTestSettings > > ( ) . InSingletonScope ( ) ;
184
- Bind < IPersistanceService < IndenterSettings > > ( ) . To < XmlPersistanceService < IndenterSettings > > ( ) . InSingletonScope ( ) ;
185
- Bind < IFilePersistanceService < SourceControlSettings > > ( ) . To < XmlPersistanceService < SourceControlSettings > > ( ) . InSingletonScope ( ) ;
186
-
187
- Bind < IIndenterConfigProvider > ( ) . To < IndenterConfigProvider > ( ) . InSingletonScope ( ) ;
188
- Bind < ISourceControlConfigProvider > ( ) . To < SourceControlConfigProvider > ( ) . InSingletonScope ( ) ;
189
-
190
- Bind < ICodeInspectionSettings > ( ) . To < CodeInspectionSettings > ( ) ;
191
- Bind < IGeneralSettings > ( ) . To < GeneralSettings > ( ) ;
192
- Bind < IHotkeySettings > ( ) . To < HotkeySettings > ( ) ;
193
- Bind < IToDoListSettings > ( ) . To < ToDoListSettings > ( ) ;
194
- Bind < IUnitTestSettings > ( ) . To < UnitTestSettings > ( ) ;
195
- Bind < IIndenterSettings > ( ) . To < IndenterSettings > ( ) ;
196
- Bind < ISourceControlSettings > ( ) . To < SourceControlSettings > ( ) ;
172
+ Bind < IPersistanceService < CodeInspectionSettings > > ( ) . To < XmlPersistanceService < CodeInspectionSettings > > ( ) . InCallScope ( ) ;
173
+ Bind < IPersistanceService < GeneralSettings > > ( ) . To < XmlPersistanceService < GeneralSettings > > ( ) . InCallScope ( ) ;
174
+ Bind < IPersistanceService < HotkeySettings > > ( ) . To < XmlPersistanceService < HotkeySettings > > ( ) . InCallScope ( ) ;
175
+ Bind < IPersistanceService < ToDoListSettings > > ( ) . To < XmlPersistanceService < ToDoListSettings > > ( ) . InCallScope ( ) ;
176
+ Bind < IPersistanceService < UnitTestSettings > > ( ) . To < XmlPersistanceService < UnitTestSettings > > ( ) . InCallScope ( ) ;
177
+ Bind < IPersistanceService < IndenterSettings > > ( ) . To < XmlPersistanceService < IndenterSettings > > ( ) . InCallScope ( ) ;
178
+ Bind < IFilePersistanceService < SourceControlSettings > > ( ) . To < XmlPersistanceService < SourceControlSettings > > ( ) . InCallScope ( ) ;
179
+
180
+ Bind < IConfigProvider < IndenterSettings > > ( ) . To < IndenterConfigProvider > ( ) . InCallScope ( ) ;
181
+ Bind < IConfigProvider < SourceControlSettings > > ( ) . To < SourceControlConfigProvider > ( ) . InCallScope ( ) ;
182
+
183
+ Bind < ICodeInspectionSettings > ( ) . To < CodeInspectionSettings > ( ) . InCallScope ( ) ;
184
+ Bind < IGeneralSettings > ( ) . To < GeneralSettings > ( ) . InCallScope ( ) ;
185
+ Bind < IHotkeySettings > ( ) . To < HotkeySettings > ( ) . InCallScope ( ) ;
186
+ Bind < IToDoListSettings > ( ) . To < ToDoListSettings > ( ) . InCallScope ( ) ;
187
+ Bind < IUnitTestSettings > ( ) . To < UnitTestSettings > ( ) . InCallScope ( ) ;
188
+ Bind < IIndenterSettings > ( ) . To < IndenterSettings > ( ) . InCallScope ( ) ;
189
+ Bind < ISourceControlSettings > ( ) . To < SourceControlSettings > ( ) . InCallScope ( ) ;
197
190
}
198
191
199
192
// note convention: abstract factory interface names end with "Factory".
@@ -220,7 +213,7 @@ private void BindCodeInspectionTypes()
220
213
{
221
214
var binding = Bind < IParseTreeInspection > ( )
222
215
. To ( inspection )
223
- . InSingletonScope ( )
216
+ . InCallScope ( )
224
217
. Named ( inspection . FullName ) ;
225
218
226
219
binding . Intercept ( ) . With < TimedCallLoggerInterceptor > ( ) ;
@@ -231,7 +224,7 @@ private void BindCodeInspectionTypes()
231
224
}
232
225
else
233
226
{
234
- var binding = Bind < IInspection > ( ) . To ( inspection ) . InSingletonScope ( ) ;
227
+ var binding = Bind < IInspection > ( ) . To ( inspection ) . InCallScope ( ) ;
235
228
binding . Intercept ( ) . With < TimedCallLoggerInterceptor > ( ) ;
236
229
binding . Intercept ( ) . With < EnumerableCounterInterceptor < InspectionResultBase > > ( ) ;
237
230
}
@@ -296,7 +289,7 @@ private void BindParentMenuItem<TParentMenu>(CommandBarControls parent, int befo
296
289
{
297
290
Bind < IParentMenuItem > ( ) . To ( typeof ( TParentMenu ) )
298
291
. WhenInjectedInto < IAppMenu > ( )
299
- . InThreadScope ( )
292
+ . InCallScope ( )
300
293
. WithConstructorArgument ( "items" , items )
301
294
. WithConstructorArgument ( "beforeIndex" , beforeIndex )
302
295
. WithPropertyValue ( "Parent" , parent ) ;
@@ -318,7 +311,7 @@ private static int FindRubberduckMenuInsertionIndex(CommandBarControls controls,
318
311
private void BindCommandsToMenuItems ( )
319
312
{
320
313
var types = Assembly . GetExecutingAssembly ( ) . GetTypes ( )
321
- . Where ( type => type . IsClass && type . Namespace != null && type . Namespace . StartsWith ( typeof ( CommandBase ) . Namespace ?? String . Empty ) )
314
+ . Where ( type => type . IsClass && type . Namespace != null && type . Namespace . StartsWith ( typeof ( CommandBase ) . Namespace ?? string . Empty ) )
322
315
. ToList ( ) ;
323
316
324
317
// note: CommandBase naming convention: [Foo]Command
@@ -340,7 +333,7 @@ private void BindCommandsToMenuItems()
340
333
binding . WhenInjectedInto < RubberduckHooks > ( ) . BindingConfiguration . Condition ;
341
334
342
335
binding . When ( request => whenCommandMenuItemCondition ( request ) || whenHooksCondition ( request ) )
343
- . InSingletonScope ( ) ;
336
+ . InCallScope ( ) ;
344
337
}
345
338
}
346
339
catch ( InvalidOperationException )
0 commit comments