Skip to content

Commit eff7929

Browse files
author
Ethan Hann
committed
Start adding dependency injection for controllers
1 parent d4f3fe1 commit eff7929

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

IntegrationEngine.Tests/Api/Controllers/CronTriggerControllerTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using IntegrationEngine;
22
using IntegrationEngine.Api.Controllers;
3+
using IntegrationEngine.Core.Storage;
34
using IntegrationEngine.Model;
45
using Moq;
56
using NUnit.Framework;
67

8+
79
namespace IntegrationEngine.Tests.Api.Controllers
810
{
911
public class CronTriggerControllerTest
@@ -21,6 +23,9 @@ public void ShouldScheduleJobWhenCronTriggerIsCreated()
2123
var engineScheduler = new Mock<IEngineScheduler>();
2224
engineScheduler.Setup(x => x.ScheduleJobWithCronTrigger(expected));
2325
subject.EngineScheduler = engineScheduler.Object;
26+
var esRepository = new Mock<ESRepository<CronTrigger>>();
27+
esRepository.Setup(x => x.Insert(expected)).Returns(expected);
28+
subject.Repository = esRepository.Object;
2429

2530
subject.PostIntegrationJob(expected);
2631

IntegrationEngine.Tests/IntegrationEngine.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<DefineConstants>DEBUG;TRACE</DefineConstants>
2828
<ErrorReport>prompt</ErrorReport>
2929
<WarningLevel>4</WarningLevel>
30+
<PlatformTarget>x86</PlatformTarget>
3031
</PropertyGroup>
3132
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3233
<DebugType>pdbonly</DebugType>
@@ -95,6 +96,10 @@
9596
<None Include="packages.config" />
9697
</ItemGroup>
9798
<ItemGroup>
99+
<ProjectReference Include="..\IntegrationEngine.Core\IntegrationEngine.Core.csproj">
100+
<Project>{3f3794d7-4078-4d26-954c-7864173edd86}</Project>
101+
<Name>IntegrationEngine.Core</Name>
102+
</ProjectReference>
98103
<ProjectReference Include="..\IntegrationEngine.Model\IntegrationEngine.Model.csproj">
99104
<Project>{0b499fe4-0bdb-4080-bcb7-f8d4ce54a4ff}</Project>
100105
<Name>IntegrationEngine.Model</Name>

IntegrationEngine.sln

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.21005.1
4+
VisualStudioVersion = 12.0.30723.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationEngine", "IntegrationEngine\IntegrationEngine.csproj", "{7D49353D-A68C-4ACA-A6A5-40B1C314C30E}"
77
EndProject
@@ -10,7 +10,9 @@ EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{DB65240B-C161-4B58-9EA8-3B490A36921E}"
1111
ProjectSection(SolutionItems) = preProject
1212
.gitignore = .gitignore
13+
package.cmd = package.cmd
1314
README.md = README.md
15+
release.cmd = release.cmd
1416
EndProjectSection
1517
EndProject
1618
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationEngine.Core", "IntegrationEngine.Core\IntegrationEngine.Core.csproj", "{3F3794D7-4078-4D26-954C-7864173EDD86}"
@@ -28,17 +30,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A9C5DD
2830
EndProject
2931
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationEngine.Tests", "IntegrationEngine.Tests\IntegrationEngine.Tests.csproj", "{820C4703-46CF-4C65-AB32-961170D96E46}"
3032
EndProject
31-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{E54079EA-35EE-4F75-9FF9-99A97EC0A831}"
32-
ProjectSection(SolutionItems) = preProject
33-
build\package.cmd = build\package.cmd
34-
build\release.cmd = build\release.cmd
35-
EndProjectSection
36-
EndProject
37-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "configuration", "configuration", "{71DC7D2A-17FC-4B14-9D1E-19E4BC8A8190}"
38-
ProjectSection(SolutionItems) = preProject
39-
configuration\IntegrationEngine.json = configuration\IntegrationEngine.json
40-
EndProjectSection
41-
EndProject
4233
Global
4334
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4435
Debug|Any CPU = Debug|Any CPU
@@ -115,10 +106,6 @@ Global
115106
GlobalSection(SolutionProperties) = preSolution
116107
HideSolutionNode = FALSE
117108
EndGlobalSection
118-
GlobalSection(NestedProjects) = preSolution
119-
{E54079EA-35EE-4F75-9FF9-99A97EC0A831} = {DB65240B-C161-4B58-9EA8-3B490A36921E}
120-
{71DC7D2A-17FC-4B14-9D1E-19E4BC8A8190} = {DB65240B-C161-4B58-9EA8-3B490A36921E}
121-
EndGlobalSection
122109
GlobalSection(MonoDevelopProperties) = preSolution
123110
StartupItem = IntegrationEngine.ConsoleHost\IntegrationEngine.ConsoleHost.csproj
124111
EndGlobalSection

IntegrationEngine/Api/Controllers/CronTriggerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class CronTriggerController : ApiController
1414

1515
public CronTriggerController()
1616
{
17-
Repository = Container.Resolve<ESRepository<CronTrigger>>();
18-
EngineScheduler = Container.Resolve<IEngineScheduler>();
17+
Repository = Container.TryResolve<ESRepository<CronTrigger>>();
18+
EngineScheduler = Container.TryResolve<IEngineScheduler>();
1919
}
2020

2121
// GET api/IntegrationJob

IntegrationEngine/Container.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public static T Resolve<T>()
88
{
99
return ContainerSingleton.GetContainer().Resolve<T>();
1010
}
11+
public static T TryResolve<T>()
12+
{
13+
return ContainerSingleton.GetContainer().TryResolve<T>();
14+
}
1115

1216
public static void Register<T>(T service)
1317
{

0 commit comments

Comments
 (0)