├── .gitattributes
├── .gitignore
├── LooseCoupling
├── AdditionalFiles
│ └── People.txt
├── Common
│ ├── Common.csproj
│ ├── IPersonRepository.cs
│ └── Person.cs
├── LateBindingAssemblies
│ ├── Newtonsoft.Json.dll
│ ├── PersonRepository.CSV.deps.json
│ ├── PersonRepository.CSV.dll
│ ├── PersonRepository.Service.deps.json
│ └── PersonRepository.Service.dll
├── LooseCoupling.sln
├── People.Service
│ ├── Controllers
│ │ └── PeopleController.cs
│ ├── Models
│ │ ├── IPeopleProvider.cs
│ │ └── StaticPeopleProvider.cs
│ ├── People.Service.csproj
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Startup.cs
│ ├── appsettings.Development.json
│ └── appsettings.json
├── PeopleViewer.Autofac.LateBinding
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Converters.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── PeopleViewer.Autofac.LateBinding.csproj
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── autofac.json
├── PeopleViewer.Autofac
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Converters.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── PeopleViewer.Autofac.csproj
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── packages.config
├── PeopleViewer.Ninject
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Converters.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── PeopleViewer.Ninject.csproj
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── packages.config
├── PeopleViewer.Presentation.Tests
│ ├── FakeRepository.cs
│ ├── PeopleViewModelTests.cs
│ ├── PeopleViewer.Presentation.Tests.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── PeopleViewer.Presentation
│ ├── PeopleViewModel.cs
│ └── PeopleViewer.Presentation.csproj
├── PeopleViewer
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Converters.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── PeopleViewer.csproj
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── packages.config
├── PersonRepository.CSV.Tests
│ ├── CSVRepositoryTests.cs
│ ├── FakeFileLoader.cs
│ ├── PersonRepository.CSV.Tests.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── TestData.cs
│ └── packages.config
├── PersonRepository.CSV
│ ├── CSVFileLoader.cs
│ ├── CSVRepository.cs
│ └── PersonRepository.CSV.csproj
├── PersonRepository.Caching
│ ├── CachingRepository.cs
│ └── PersonRepository.Caching.csproj
└── PersonRepository.Service
│ ├── PersonRepository.Service.csproj
│ └── ServiceRepository.cs
├── README.md
├── SLIDES-DependencyInjection.pdf
└── TightCoupling
├── Common
├── Common.csproj
└── Person.cs
├── People.Service
├── Controllers
│ └── PeopleController.cs
├── Models
│ ├── IPeopleProvider.cs
│ └── StaticPeopleProvider.cs
├── People.Service.csproj
├── Program.cs
├── Properties
│ └── launchSettings.json
├── Startup.cs
├── appsettings.Development.json
└── appsettings.json
├── PeopleViewer.Presentation
├── PeopleViewModel.cs
└── PeopleViewer.Presentation.csproj
├── PeopleViewer
├── App.config
├── App.xaml
├── App.xaml.cs
├── Converters.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── PeopleViewer.csproj
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── packages.config
├── PersonRepository.Service
├── PersonRepository.Service.csproj
└── ServiceRepository.cs
└── TightCoupling.sln
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 |
84 | # Visual Studio profiler
85 | *.psess
86 | *.vsp
87 | *.vspx
88 | *.sap
89 |
90 | # TFS 2012 Local Workspace
91 | $tf/
92 |
93 | # Guidance Automation Toolkit
94 | *.gpState
95 |
96 | # ReSharper is a .NET coding add-in
97 | _ReSharper*/
98 | *.[Rr]e[Ss]harper
99 | *.DotSettings.user
100 |
101 | # JustCode is a .NET coding add-in
102 | .JustCode
103 |
104 | # TeamCity is a build add-in
105 | _TeamCity*
106 |
107 | # DotCover is a Code Coverage Tool
108 | *.dotCover
109 |
110 | # NCrunch
111 | _NCrunch_*
112 | .*crunch*.local.xml
113 | nCrunchTemp_*
114 |
115 | # MightyMoose
116 | *.mm.*
117 | AutoTest.Net/
118 |
119 | # Web workbench (sass)
120 | .sass-cache/
121 |
122 | # Installshield output folder
123 | [Ee]xpress/
124 |
125 | # DocProject is a documentation generator add-in
126 | DocProject/buildhelp/
127 | DocProject/Help/*.HxT
128 | DocProject/Help/*.HxC
129 | DocProject/Help/*.hhc
130 | DocProject/Help/*.hhk
131 | DocProject/Help/*.hhp
132 | DocProject/Help/Html2
133 | DocProject/Help/html
134 |
135 | # Click-Once directory
136 | publish/
137 |
138 | # Publish Web Output
139 | *.[Pp]ublish.xml
140 | *.azurePubxml
141 | # TODO: Comment the next line if you want to checkin your web deploy settings
142 | # but database connection strings (with potential passwords) will be unencrypted
143 | *.pubxml
144 | *.publishproj
145 |
146 | # NuGet Packages
147 | *.nupkg
148 | # The packages folder can be ignored because of Package Restore
149 | **/packages/*
150 | # except build/, which is used as an MSBuild target.
151 | !**/packages/build/
152 | # Uncomment if necessary however generally it will be regenerated when needed
153 | #!**/packages/repositories.config
154 | # NuGet v3's project.json files produces more ignoreable files
155 | *.nuget.props
156 | *.nuget.targets
157 |
158 | # Microsoft Azure Build Output
159 | csx/
160 | *.build.csdef
161 |
162 | # Microsoft Azure Emulator
163 | ecf/
164 | rcf/
165 |
166 | # Microsoft Azure ApplicationInsights config file
167 | ApplicationInsights.config
168 |
169 | # Windows Store app package directory
170 | AppPackages/
171 | BundleArtifacts/
172 |
173 | # Visual Studio cache files
174 | # files ending in .cache can be ignored
175 | *.[Cc]ache
176 | # but keep track of directories ending in .cache
177 | !*.[Cc]ache/
178 |
179 | # Others
180 | ClientBin/
181 | ~$*
182 | *~
183 | *.dbmdl
184 | *.dbproj.schemaview
185 | *.pfx
186 | *.publishsettings
187 | node_modules/
188 | orleans.codegen.cs
189 |
190 | # RIA/Silverlight projects
191 | Generated_Code/
192 |
193 | # Backup & report files from converting an old project file
194 | # to a newer Visual Studio version. Backup files are not needed,
195 | # because we have git ;-)
196 | _UpgradeReport_Files/
197 | Backup*/
198 | UpgradeLog*.XML
199 | UpgradeLog*.htm
200 |
201 | # SQL Server files
202 | *.mdf
203 | *.ldf
204 |
205 | # Business Intelligence projects
206 | *.rdl.data
207 | *.bim.layout
208 | *.bim_*.settings
209 |
210 | # Microsoft Fakes
211 | FakesAssemblies/
212 |
213 | # GhostDoc plugin setting file
214 | *.GhostDoc.xml
215 |
216 | # Node.js Tools for Visual Studio
217 | .ntvs_analysis.dat
218 |
219 | # Visual Studio 6 build log
220 | *.plg
221 |
222 | # Visual Studio 6 workspace options file
223 | *.opt
224 |
225 | # Visual Studio LightSwitch build output
226 | **/*.HTMLClient/GeneratedArtifacts
227 | **/*.DesktopClient/GeneratedArtifacts
228 | **/*.DesktopClient/ModelManifest.xml
229 | **/*.Server/GeneratedArtifacts
230 | **/*.Server/ModelManifest.xml
231 | _Pvt_Extensions
232 |
233 | # Paket dependency manager
234 | .paket/paket.exe
235 |
236 | # FAKE - F# Make
237 | .fake/
--------------------------------------------------------------------------------
/LooseCoupling/AdditionalFiles/People.txt:
--------------------------------------------------------------------------------
1 | 1,John,Koenig,1975/10/17,6,
2 | 2,Dylan,Hunt,2000/10/02,8,
3 | 3,Leela,Turanga,1999/3/28,8,{1} {0}
4 | 4,John,Crichton,1999/03/19,7,
5 | 5,Dave,Lister,1988/02/15,9,
6 | 6,Laura,Roslin,2003/12/8,6,
7 | 7,John,Sheridan,1994/01/26,6,
8 | 8,Dante,Montana,2000/11/01,5,
9 | 9,Isaac,Gampu,1977/09/10,4,
10 | 10,Jeremy,Awesome,1971/05/03,10,
--------------------------------------------------------------------------------
/LooseCoupling/Common/Common.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LooseCoupling/Common/IPersonRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 |
4 | namespace Common
5 | {
6 | public interface IPersonRepository
7 | {
8 | IEnumerable GetPeople();
9 | Person GetPerson(int id);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/LooseCoupling/Common/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Common
4 | {
5 | public class Person
6 | {
7 | public int Id { get; set; }
8 | public string GivenName { get; set; }
9 | public string FamilyName { get; set; }
10 | public DateTime StartDate { get; set; }
11 | public int Rating { get; set; }
12 | public string FormatString { get; set; }
13 |
14 | public override string ToString()
15 | {
16 | if (string.IsNullOrEmpty(FormatString))
17 | FormatString = "{0} {1}";
18 | return string.Format(FormatString, GivenName, FamilyName);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/LooseCoupling/LateBindingAssemblies/Newtonsoft.Json.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeremybytes/learning-dependency-injection/116f6fb26ee661b8055808229aeba3ccfaff7b49/LooseCoupling/LateBindingAssemblies/Newtonsoft.Json.dll
--------------------------------------------------------------------------------
/LooseCoupling/LateBindingAssemblies/PersonRepository.CSV.deps.json:
--------------------------------------------------------------------------------
1 | {
2 | "runtimeTarget": {
3 | "name": ".NETStandard,Version=v2.0/",
4 | "signature": ""
5 | },
6 | "compilationOptions": {},
7 | "targets": {
8 | ".NETStandard,Version=v2.0": {},
9 | ".NETStandard,Version=v2.0/": {
10 | "PersonRepository.CSV/1.0.0": {
11 | "dependencies": {
12 | "Common": "1.0.0",
13 | "NETStandard.Library": "2.0.3"
14 | },
15 | "runtime": {
16 | "PersonRepository.CSV.dll": {}
17 | }
18 | },
19 | "Microsoft.NETCore.Platforms/1.1.0": {},
20 | "NETStandard.Library/2.0.3": {
21 | "dependencies": {
22 | "Microsoft.NETCore.Platforms": "1.1.0"
23 | }
24 | },
25 | "Common/1.0.0": {
26 | "runtime": {
27 | "Common.dll": {}
28 | }
29 | }
30 | }
31 | },
32 | "libraries": {
33 | "PersonRepository.CSV/1.0.0": {
34 | "type": "project",
35 | "serviceable": false,
36 | "sha512": ""
37 | },
38 | "Microsoft.NETCore.Platforms/1.1.0": {
39 | "type": "package",
40 | "serviceable": true,
41 | "sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
42 | "path": "microsoft.netcore.platforms/1.1.0",
43 | "hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
44 | },
45 | "NETStandard.Library/2.0.3": {
46 | "type": "package",
47 | "serviceable": true,
48 | "sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
49 | "path": "netstandard.library/2.0.3",
50 | "hashPath": "netstandard.library.2.0.3.nupkg.sha512"
51 | },
52 | "Common/1.0.0": {
53 | "type": "project",
54 | "serviceable": false,
55 | "sha512": ""
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/LooseCoupling/LateBindingAssemblies/PersonRepository.CSV.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeremybytes/learning-dependency-injection/116f6fb26ee661b8055808229aeba3ccfaff7b49/LooseCoupling/LateBindingAssemblies/PersonRepository.CSV.dll
--------------------------------------------------------------------------------
/LooseCoupling/LateBindingAssemblies/PersonRepository.Service.deps.json:
--------------------------------------------------------------------------------
1 | {
2 | "runtimeTarget": {
3 | "name": ".NETStandard,Version=v2.0/",
4 | "signature": ""
5 | },
6 | "compilationOptions": {},
7 | "targets": {
8 | ".NETStandard,Version=v2.0": {},
9 | ".NETStandard,Version=v2.0/": {
10 | "PersonRepository.Service/1.0.0": {
11 | "dependencies": {
12 | "Common": "1.0.0",
13 | "NETStandard.Library": "2.0.3",
14 | "Newtonsoft.Json": "11.0.2"
15 | },
16 | "runtime": {
17 | "PersonRepository.Service.dll": {}
18 | }
19 | },
20 | "Microsoft.NETCore.Platforms/1.1.0": {},
21 | "NETStandard.Library/2.0.3": {
22 | "dependencies": {
23 | "Microsoft.NETCore.Platforms": "1.1.0"
24 | }
25 | },
26 | "Newtonsoft.Json/11.0.2": {
27 | "runtime": {
28 | "lib/netstandard2.0/Newtonsoft.Json.dll": {
29 | "assemblyVersion": "11.0.0.0",
30 | "fileVersion": "11.0.2.21924"
31 | }
32 | }
33 | },
34 | "Common/1.0.0": {
35 | "runtime": {
36 | "Common.dll": {}
37 | }
38 | }
39 | }
40 | },
41 | "libraries": {
42 | "PersonRepository.Service/1.0.0": {
43 | "type": "project",
44 | "serviceable": false,
45 | "sha512": ""
46 | },
47 | "Microsoft.NETCore.Platforms/1.1.0": {
48 | "type": "package",
49 | "serviceable": true,
50 | "sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
51 | "path": "microsoft.netcore.platforms/1.1.0",
52 | "hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
53 | },
54 | "NETStandard.Library/2.0.3": {
55 | "type": "package",
56 | "serviceable": true,
57 | "sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
58 | "path": "netstandard.library/2.0.3",
59 | "hashPath": "netstandard.library.2.0.3.nupkg.sha512"
60 | },
61 | "Newtonsoft.Json/11.0.2": {
62 | "type": "package",
63 | "serviceable": true,
64 | "sha512": "sha512-IvJe1pj7JHEsP8B8J8DwlMEx8UInrs/x+9oVY+oCD13jpLu4JbJU2WCIsMRn5C4yW9+DgkaO8uiVE5VHKjpmdQ==",
65 | "path": "newtonsoft.json/11.0.2",
66 | "hashPath": "newtonsoft.json.11.0.2.nupkg.sha512"
67 | },
68 | "Common/1.0.0": {
69 | "type": "project",
70 | "serviceable": false,
71 | "sha512": ""
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/LooseCoupling/LateBindingAssemblies/PersonRepository.Service.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeremybytes/learning-dependency-injection/116f6fb26ee661b8055808229aeba3ccfaff7b49/LooseCoupling/LateBindingAssemblies/PersonRepository.Service.dll
--------------------------------------------------------------------------------
/LooseCoupling/LooseCoupling.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28803.202
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{1B82B92C-6693-4922-AE9A-9CACB5C4E24F}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "People.Service", "People.Service\People.Service.csproj", "{7CA7ABCC-8065-423F-964E-0135D83ADB02}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{817DFB31-DAED-403F-9FAD-312AF1E2CE89}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04-Data Storage", "04-Data Storage", "{7C50B4E7-1FB5-45B6-8AB3-5C0409109CB3}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeopleViewer", "PeopleViewer\PeopleViewer.csproj", "{E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01-Application View", "01-Application View", "{DB58D260-0DDF-45D3-9A65-9D0464733819}"
17 | EndProject
18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-Presentation", "02-Presentation", "{E46C5347-AEE9-4C96-96BC-F1B0C549A01C}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeopleViewer.Presentation", "PeopleViewer.Presentation\PeopleViewer.Presentation.csproj", "{12581640-1ECC-44D0-9A6B-66B28FFFE65F}"
21 | EndProject
22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03-Data Access", "03-Data Access", "{A7B96D7E-CCC5-42B8-964F-D87FE42B0074}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PersonRepository.Service", "PersonRepository.Service\PersonRepository.Service.csproj", "{F0DB1627-F716-44AF-B545-E4A649EDD771}"
25 | EndProject
26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PersonRepository.CSV", "PersonRepository.CSV\PersonRepository.CSV.csproj", "{1174395B-80CF-4109-B049-E6F041C4B9A9}"
27 | EndProject
28 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PersonRepository.Caching", "PersonRepository.Caching\PersonRepository.Caching.csproj", "{1A21A62F-0A90-4F94-88AA-341C730F54A7}"
29 | EndProject
30 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Testing", "Testing", "{AC3CFB83-BBF1-4AFD-ADEE-87DCA241A885}"
31 | EndProject
32 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeopleViewer.Presentation.Tests", "PeopleViewer.Presentation.Tests\PeopleViewer.Presentation.Tests.csproj", "{8BB096F4-1DB0-4038-BA69-A4F75406D336}"
33 | EndProject
34 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeopleViewer.Ninject", "PeopleViewer.Ninject\PeopleViewer.Ninject.csproj", "{A8F28521-413D-4E59-82AD-24C6D2B1DA4B}"
35 | EndProject
36 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonRepository.CSV.Tests", "PersonRepository.CSV.Tests\PersonRepository.CSV.Tests.csproj", "{CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE}"
37 | EndProject
38 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeopleViewer.Autofac", "PeopleViewer.Autofac\PeopleViewer.Autofac.csproj", "{1997D367-7DED-497B-9966-A16A8D269C21}"
39 | EndProject
40 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeopleViewer.Autofac.LateBinding", "PeopleViewer.Autofac.LateBinding\PeopleViewer.Autofac.LateBinding.csproj", "{FB1D1F9B-50D9-403B-8F29-43B4A3F421D1}"
41 | EndProject
42 | Global
43 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
44 | Debug|Any CPU = Debug|Any CPU
45 | Release|Any CPU = Release|Any CPU
46 | EndGlobalSection
47 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
48 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Debug|Any CPU.Build.0 = Debug|Any CPU
62 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Release|Any CPU.ActiveCfg = Release|Any CPU
63 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Release|Any CPU.Build.0 = Release|Any CPU
64 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Debug|Any CPU.Build.0 = Debug|Any CPU
66 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Release|Any CPU.ActiveCfg = Release|Any CPU
67 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Release|Any CPU.Build.0 = Release|Any CPU
68 | {1174395B-80CF-4109-B049-E6F041C4B9A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69 | {1174395B-80CF-4109-B049-E6F041C4B9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
70 | {1174395B-80CF-4109-B049-E6F041C4B9A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
71 | {1174395B-80CF-4109-B049-E6F041C4B9A9}.Release|Any CPU.Build.0 = Release|Any CPU
72 | {1A21A62F-0A90-4F94-88AA-341C730F54A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73 | {1A21A62F-0A90-4F94-88AA-341C730F54A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
74 | {1A21A62F-0A90-4F94-88AA-341C730F54A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
75 | {1A21A62F-0A90-4F94-88AA-341C730F54A7}.Release|Any CPU.Build.0 = Release|Any CPU
76 | {8BB096F4-1DB0-4038-BA69-A4F75406D336}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77 | {8BB096F4-1DB0-4038-BA69-A4F75406D336}.Debug|Any CPU.Build.0 = Debug|Any CPU
78 | {8BB096F4-1DB0-4038-BA69-A4F75406D336}.Release|Any CPU.ActiveCfg = Release|Any CPU
79 | {8BB096F4-1DB0-4038-BA69-A4F75406D336}.Release|Any CPU.Build.0 = Release|Any CPU
80 | {A8F28521-413D-4E59-82AD-24C6D2B1DA4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
81 | {A8F28521-413D-4E59-82AD-24C6D2B1DA4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
82 | {A8F28521-413D-4E59-82AD-24C6D2B1DA4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
83 | {A8F28521-413D-4E59-82AD-24C6D2B1DA4B}.Release|Any CPU.Build.0 = Release|Any CPU
84 | {CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
85 | {CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
86 | {CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
87 | {CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE}.Release|Any CPU.Build.0 = Release|Any CPU
88 | {1997D367-7DED-497B-9966-A16A8D269C21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
89 | {1997D367-7DED-497B-9966-A16A8D269C21}.Debug|Any CPU.Build.0 = Debug|Any CPU
90 | {1997D367-7DED-497B-9966-A16A8D269C21}.Release|Any CPU.ActiveCfg = Release|Any CPU
91 | {1997D367-7DED-497B-9966-A16A8D269C21}.Release|Any CPU.Build.0 = Release|Any CPU
92 | {FB1D1F9B-50D9-403B-8F29-43B4A3F421D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93 | {FB1D1F9B-50D9-403B-8F29-43B4A3F421D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
94 | {FB1D1F9B-50D9-403B-8F29-43B4A3F421D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
95 | {FB1D1F9B-50D9-403B-8F29-43B4A3F421D1}.Release|Any CPU.Build.0 = Release|Any CPU
96 | EndGlobalSection
97 | GlobalSection(SolutionProperties) = preSolution
98 | HideSolutionNode = FALSE
99 | EndGlobalSection
100 | GlobalSection(NestedProjects) = preSolution
101 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F} = {817DFB31-DAED-403F-9FAD-312AF1E2CE89}
102 | {7CA7ABCC-8065-423F-964E-0135D83ADB02} = {7C50B4E7-1FB5-45B6-8AB3-5C0409109CB3}
103 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A} = {DB58D260-0DDF-45D3-9A65-9D0464733819}
104 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F} = {E46C5347-AEE9-4C96-96BC-F1B0C549A01C}
105 | {F0DB1627-F716-44AF-B545-E4A649EDD771} = {A7B96D7E-CCC5-42B8-964F-D87FE42B0074}
106 | {1174395B-80CF-4109-B049-E6F041C4B9A9} = {A7B96D7E-CCC5-42B8-964F-D87FE42B0074}
107 | {1A21A62F-0A90-4F94-88AA-341C730F54A7} = {A7B96D7E-CCC5-42B8-964F-D87FE42B0074}
108 | {8BB096F4-1DB0-4038-BA69-A4F75406D336} = {AC3CFB83-BBF1-4AFD-ADEE-87DCA241A885}
109 | {A8F28521-413D-4E59-82AD-24C6D2B1DA4B} = {DB58D260-0DDF-45D3-9A65-9D0464733819}
110 | {CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE} = {AC3CFB83-BBF1-4AFD-ADEE-87DCA241A885}
111 | {1997D367-7DED-497B-9966-A16A8D269C21} = {DB58D260-0DDF-45D3-9A65-9D0464733819}
112 | {FB1D1F9B-50D9-403B-8F29-43B4A3F421D1} = {DB58D260-0DDF-45D3-9A65-9D0464733819}
113 | EndGlobalSection
114 | GlobalSection(ExtensibilityGlobals) = postSolution
115 | SolutionGuid = {62280A51-57F7-4AEB-B108-3A00B1574DEA}
116 | EndGlobalSection
117 | EndGlobal
118 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/Controllers/PeopleController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Microsoft.AspNetCore.Mvc;
4 | using People.Service.Models;
5 | using Common;
6 |
7 | namespace People.Service.Controllers
8 | {
9 | [Route("api/[controller]")]
10 | [ApiController]
11 | public class PeopleController : ControllerBase
12 | {
13 | IPeopleProvider provider;
14 |
15 | public PeopleController(IPeopleProvider provider)
16 | {
17 | this.provider = provider;
18 | }
19 |
20 | // GET api/values
21 | [HttpGet]
22 | public IEnumerable Get()
23 | {
24 | return provider.GetPeople();
25 | }
26 |
27 | // GET api/values/5
28 | [HttpGet("{id}")]
29 | public Person Get(int id)
30 | {
31 | return provider.GetPeople().FirstOrDefault(p => p.Id == id);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/Models/IPeopleProvider.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System.Collections.Generic;
3 |
4 | namespace People.Service.Models
5 | {
6 | public interface IPeopleProvider
7 | {
8 | List GetPeople();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/Models/StaticPeopleProvider.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace People.Service.Models
6 | {
7 | public class StaticPeopleProvider : IPeopleProvider
8 | {
9 | public List GetPeople()
10 | {
11 | var p = new List()
12 | {
13 | new Person() { Id=1, GivenName="John", FamilyName="Koenig",
14 | StartDate = new DateTime(1975, 10, 17), Rating=6 },
15 | new Person() { Id=2, GivenName="Dylan", FamilyName="Hunt",
16 | StartDate = new DateTime(2000, 10, 2), Rating=8 },
17 | new Person() { Id=3, GivenName="Leela", FamilyName="Turanga",
18 | StartDate = new DateTime(1999, 3, 28), Rating=8,
19 | FormatString = "{1} {0}" },
20 | new Person() { Id=4, GivenName="John", FamilyName="Crichton",
21 | StartDate = new DateTime(1999, 3, 19), Rating=7 },
22 | new Person() { Id=5, GivenName="Dave", FamilyName="Lister",
23 | StartDate = new DateTime(1988, 2, 15), Rating=9 },
24 | new Person() { Id=6, GivenName="Laura", FamilyName="Roslin",
25 | StartDate = new DateTime(2003, 12, 8), Rating=6},
26 | new Person() { Id=7, GivenName="John", FamilyName="Sheridan",
27 | StartDate = new DateTime(1994, 1, 26), Rating=6 },
28 | new Person() { Id=8, GivenName="Dante", FamilyName="Montana",
29 | StartDate = new DateTime(2000, 11, 1), Rating=5 },
30 | new Person() { Id=9, GivenName="Isaac", FamilyName="Gampu",
31 | StartDate = new DateTime(1977, 9, 10), Rating=4 },
32 | };
33 | return p;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/People.Service.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 | InProcess
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 |
4 | namespace People.Service
5 | {
6 | public class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | CreateWebHostBuilder(args).Build().Run();
11 | }
12 |
13 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
14 | WebHost.CreateDefaultBuilder(args)
15 | .UseStartup()
16 | .UseUrls("http://localhost:9874");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:32101",
8 | "sslPort": 44340
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "api/values",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "People.Service": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "api/values",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Builder;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.Extensions.Configuration;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using People.Service.Models;
7 |
8 | namespace People.Service
9 | {
10 | public class Startup
11 | {
12 | public Startup(IConfiguration configuration)
13 | {
14 | Configuration = configuration;
15 | }
16 |
17 | public IConfiguration Configuration { get; }
18 |
19 | // This method gets called by the runtime. Use this method to add services to the container.
20 | public void ConfigureServices(IServiceCollection services)
21 | {
22 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
23 | services.AddSingleton();
24 | }
25 |
26 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
27 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
28 | {
29 | if (env.IsDevelopment())
30 | {
31 | app.UseDeveloperExceptionPage();
32 | }
33 | app.UseMvc();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/LooseCoupling/People.Service/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*"
8 | }
9 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Autofac.Configuration;
3 | using Microsoft.Extensions.Configuration;
4 | using PeopleViewer.Presentation;
5 | using System.Windows;
6 |
7 | namespace PeopleViewer.Autofac.LateBinding
8 | {
9 | public partial class App : Application
10 | {
11 | IContainer Container;
12 |
13 | protected override void OnStartup(StartupEventArgs e)
14 | {
15 | base.OnStartup(e);
16 | ConfigureContainer();
17 | ComposeObjects();
18 | Application.Current.MainWindow.Title = "With Dependency Injection - Autofac Late Binding";
19 | Application.Current.MainWindow.Show();
20 | }
21 |
22 | private void ConfigureContainer()
23 | {
24 | var config = new ConfigurationBuilder();
25 | config.AddJsonFile("autofac.json");
26 |
27 | var module = new ConfigurationModule(config.Build());
28 | var builder = new ContainerBuilder();
29 | builder.RegisterModule(module);
30 |
31 | builder.RegisterType().InstancePerDependency();
32 | builder.RegisterType().InstancePerDependency();
33 |
34 | Container = builder.Build();
35 | }
36 |
37 | private void ComposeObjects()
38 | {
39 | Application.Current.MainWindow = Container.Resolve();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/Converters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Windows.Data;
4 | using System.Windows.Media;
5 |
6 | namespace PeopleViewer.Autofac.LateBinding
7 | {
8 | public class DecadeConverter : IValueConverter
9 | {
10 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
11 | {
12 | int year = ((DateTime)value).Year;
13 | return string.Format("{0}0s", year.ToString().Substring(0, 3));
14 | }
15 |
16 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
17 | {
18 | throw new NotImplementedException();
19 | }
20 | }
21 |
22 | public class RatingConverter : IValueConverter
23 | {
24 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
25 | {
26 | int rating = (int)value;
27 | return string.Format("{0}/10 Stars", rating.ToString());
28 | }
29 |
30 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
31 | {
32 | throw new NotImplementedException();
33 | }
34 | }
35 |
36 | public class RatingStarConverter : IValueConverter
37 | {
38 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
39 | {
40 | int rating = (int)value;
41 | string output = string.Empty;
42 | return output.PadLeft(rating, '*');
43 | }
44 |
45 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
46 | {
47 | string input = (string)value;
48 | //int rating = 0;
49 |
50 | //foreach (var ch in input)
51 | // if (ch == '*')
52 | // rating++;
53 |
54 | //return rating;
55 |
56 | return input.Count(c => c == '*');
57 | }
58 | }
59 |
60 | public class DecadeBrushConverter : IValueConverter
61 | {
62 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
63 | {
64 | int decade = (((DateTime)value).Year / 10) * 10;
65 |
66 | switch (decade)
67 | {
68 | case 1970:
69 | return new SolidColorBrush(Colors.Maroon);
70 | case 1980:
71 | return new SolidColorBrush(Colors.DarkGreen);
72 | case 1990:
73 | return new SolidColorBrush(Colors.DarkSlateBlue);
74 | case 2000:
75 | return new SolidColorBrush(Colors.CadetBlue);
76 | default:
77 | return new SolidColorBrush(Colors.DarkSlateGray);
78 | }
79 | }
80 |
81 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
82 | {
83 | throw new NotImplementedException();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
39 |
40 |
41 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using PeopleViewer.Presentation;
2 | using System.Windows;
3 |
4 | namespace PeopleViewer.Autofac.LateBinding
5 | {
6 | public partial class MainWindow : Window
7 | {
8 | PeopleViewModel ViewModel { get; set; }
9 |
10 | public MainWindow(PeopleViewModel viewModel)
11 | {
12 | InitializeComponent();
13 | ViewModel = viewModel;
14 | DataContext = ViewModel;
15 | }
16 |
17 | private void RefreshButton_Click(object sender, RoutedEventArgs e)
18 | {
19 | ViewModel.RefreshPeople();
20 | }
21 |
22 | private void ClearButton_Click(object sender, RoutedEventArgs e)
23 | {
24 | ViewModel.ClearPeople();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/PeopleViewer.Autofac.LateBinding.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PackageReference
6 | Debug
7 | AnyCPU
8 | {FB1D1F9B-50D9-403B-8F29-43B4A3F421D1}
9 | WinExe
10 | PeopleViewer.Autofac.LateBinding
11 | PeopleViewer.Autofac.LateBinding
12 | v4.7.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 | true
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 4.0
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | MSBuild:Compile
57 | Designer
58 |
59 |
60 | App.xaml
61 | Code
62 |
63 |
64 |
65 |
66 |
67 | MainWindow.xaml
68 |
69 |
70 | Code
71 |
72 |
73 | True
74 | True
75 | Resources.resx
76 |
77 |
78 | True
79 | Settings.settings
80 | True
81 |
82 |
83 | ResXFileCodeGenerator
84 | Resources.Designer.cs
85 |
86 |
87 | Always
88 |
89 |
90 | SettingsSingleFileGenerator
91 | Settings.Designer.cs
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | {1b82b92c-6693-4922-ae9a-9cacb5c4e24f}
100 | Common
101 |
102 |
103 | {952dade9-b379-4ef2-aa13-781a847818ec}
104 | PeopleViewer.Presentation
105 |
106 |
107 |
108 |
109 | 4.9.2
110 |
111 |
112 | 4.1.0
113 |
114 |
115 | 2.2.0
116 |
117 |
118 | 2.2.0
119 |
120 |
121 |
122 |
123 | MSBuild:Compile
124 | Designer
125 |
126 |
127 |
128 |
129 | xcopy "$(SolutionDir)AdditionalFiles\*.*" "$(TargetDir)" /Y
130 | xcopy "$(SolutionDir)LateBindingAssemblies\*.*" "$(TargetDir)" /Y
131 |
132 |
133 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeopleViewer.Autofac.LateBinding")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeopleViewer.Autofac.LateBinding")]
15 | [assembly: AssemblyCopyright("Copyright © 2019")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Autofac.LateBinding.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeopleViewer.Autofac.LateBinding.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Autofac.LateBinding.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac.LateBinding/autofac.json:
--------------------------------------------------------------------------------
1 | {
2 | "components": [
3 | {
4 | "type": "PersonRepository.Service.ServiceRepository, PersonRepository.Service",
5 | "services": [
6 | {
7 | "type": "Common.IPersonRepository, Common"
8 | }
9 | ],
10 | "injectionProperties": false
11 | }
12 | ]
13 | }
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Autofac.Features.ResolveAnything;
3 | using Common;
4 | using PeopleViewer.Presentation;
5 | using PersonRepository.Caching;
6 | using PersonRepository.Service;
7 | using PersonRepository.CSV;
8 | using System.Windows;
9 |
10 | namespace PeopleViewer.Autofac
11 | {
12 | public partial class App : Application
13 | {
14 | IContainer Container;
15 |
16 | protected override void OnStartup(StartupEventArgs e)
17 | {
18 | base.OnStartup(e);
19 | ConfigureContainer();
20 | ComposeObjects();
21 | Application.Current.MainWindow.Title = "With Dependency Injection - Autofac";
22 | Application.Current.MainWindow.Show();
23 | }
24 |
25 | private void ConfigureContainer()
26 | {
27 | var builder = new ContainerBuilder();
28 |
29 | // DATA READER TYPE OPTION #1 - No Decorator
30 | //builder.RegisterType().As()
31 | // .SingleInstance();
32 |
33 | // DATA READER TYPE OPTION #2 - With Decorator
34 | builder.RegisterType().Named("repository")
35 | .SingleInstance();
36 | builder.RegisterDecorator(
37 | (c, inner) => new CachingRepository(inner), fromKey: "repository");
38 |
39 | // OTHER TYPES OPTION #1 - Automatic Registration
40 | //builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
41 |
42 | // OTHER TYPES OPTION #2 - Explicit Registration
43 | builder.RegisterType().InstancePerDependency();
44 | builder.RegisterType().InstancePerDependency();
45 |
46 | Container = builder.Build();
47 | }
48 |
49 | private void ComposeObjects()
50 | {
51 | Application.Current.MainWindow = Container.Resolve();
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/Converters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Windows.Data;
4 | using System.Windows.Media;
5 |
6 | namespace PeopleViewer.Autofac
7 | {
8 | public class DecadeConverter : IValueConverter
9 | {
10 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
11 | {
12 | int year = ((DateTime)value).Year;
13 | return string.Format("{0}0s", year.ToString().Substring(0, 3));
14 | }
15 |
16 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
17 | {
18 | throw new NotImplementedException();
19 | }
20 | }
21 |
22 | public class RatingConverter : IValueConverter
23 | {
24 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
25 | {
26 | int rating = (int)value;
27 | return string.Format("{0}/10 Stars", rating.ToString());
28 | }
29 |
30 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
31 | {
32 | throw new NotImplementedException();
33 | }
34 | }
35 |
36 | public class RatingStarConverter : IValueConverter
37 | {
38 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
39 | {
40 | int rating = (int)value;
41 | string output = string.Empty;
42 | return output.PadLeft(rating, '*');
43 | }
44 |
45 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
46 | {
47 | string input = (string)value;
48 | //int rating = 0;
49 |
50 | //foreach (var ch in input)
51 | // if (ch == '*')
52 | // rating++;
53 |
54 | //return rating;
55 |
56 | return input.Count(c => c == '*');
57 | }
58 | }
59 |
60 | public class DecadeBrushConverter : IValueConverter
61 | {
62 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
63 | {
64 | int decade = (((DateTime)value).Year / 10) * 10;
65 |
66 | switch (decade)
67 | {
68 | case 1970:
69 | return new SolidColorBrush(Colors.Maroon);
70 | case 1980:
71 | return new SolidColorBrush(Colors.DarkGreen);
72 | case 1990:
73 | return new SolidColorBrush(Colors.DarkSlateBlue);
74 | case 2000:
75 | return new SolidColorBrush(Colors.CadetBlue);
76 | default:
77 | return new SolidColorBrush(Colors.DarkSlateGray);
78 | }
79 | }
80 |
81 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
82 | {
83 | throw new NotImplementedException();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
39 |
40 |
41 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using PeopleViewer.Presentation;
2 | using System.Windows;
3 |
4 | namespace PeopleViewer.Autofac
5 | {
6 | public partial class MainWindow : Window
7 | {
8 | PeopleViewModel ViewModel { get; set; }
9 |
10 | public MainWindow(PeopleViewModel viewModel)
11 | {
12 | InitializeComponent();
13 | ViewModel = viewModel;
14 | DataContext = ViewModel;
15 | }
16 |
17 | private void RefreshButton_Click(object sender, RoutedEventArgs e)
18 | {
19 | ViewModel.RefreshPeople();
20 | }
21 |
22 | private void ClearButton_Click(object sender, RoutedEventArgs e)
23 | {
24 | ViewModel.ClearPeople();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/PeopleViewer.Autofac.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PackageReference
6 | Debug
7 | AnyCPU
8 | {1997D367-7DED-497B-9966-A16A8D269C21}
9 | WinExe
10 | PeopleViewer.Autofac
11 | PeopleViewer.Autofac
12 | v4.7.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 | true
18 |
19 |
20 | AnyCPU
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | AnyCPU
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 4.0
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | MSBuild:Compile
57 | Designer
58 |
59 |
60 | App.xaml
61 | Code
62 |
63 |
64 |
65 |
66 |
67 | MainWindow.xaml
68 |
69 |
70 | Code
71 |
72 |
73 | True
74 | True
75 | Resources.resx
76 |
77 |
78 | True
79 | Settings.settings
80 | True
81 |
82 |
83 | ResXFileCodeGenerator
84 | Resources.Designer.cs
85 |
86 |
87 |
88 | SettingsSingleFileGenerator
89 | Settings.Designer.cs
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 | {1b82b92c-6693-4922-ae9a-9cacb5c4e24f}
98 | Common
99 |
100 |
101 | {952dade9-b379-4ef2-aa13-781a847818ec}
102 | PeopleViewer.Presentation
103 |
104 |
105 | {1a21a62f-0a90-4f94-88aa-341c730f54a7}
106 | PersonRepository.Caching
107 |
108 |
109 | {1174395b-80cf-4109-b049-e6f041c4b9a9}
110 | PersonRepository.CSV
111 |
112 |
113 | {f0db1627-f716-44af-b545-e4a649edd771}
114 | PersonRepository.Service
115 |
116 |
117 |
118 |
119 | 4.9.1
120 |
121 |
122 |
123 |
124 | MSBuild:Compile
125 | Designer
126 |
127 |
128 |
129 |
130 | xcopy "$(SolutionDir)AdditionalFiles\*.*" "$(TargetDir)" /Y
131 |
132 |
133 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeopleViewer.Autofac")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeopleViewer.Autofac")]
15 | [assembly: AssemblyCopyright("Copyright © 2019")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Autofac.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeopleViewer.Autofac.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Autofac.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Autofac/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using Ninject;
3 | using PersonRepository.Caching;
4 | using PersonRepository.CSV;
5 | using PersonRepository.Service;
6 | using System.Windows;
7 |
8 | namespace PeopleViewer.Ninject
9 | {
10 | public partial class App : Application
11 | {
12 | IKernel Container;
13 |
14 | protected override void OnStartup(StartupEventArgs e)
15 | {
16 | base.OnStartup(e);
17 | ConfigureContainer();
18 | ComposeObjects();
19 | Application.Current.MainWindow.Show();
20 | }
21 |
22 | private void ConfigureContainer()
23 | {
24 | Container = new StandardKernel();
25 | Container.Bind().To()
26 | .InSingletonScope()
27 | .WithConstructorArgument(
28 | Container.Get());
29 | }
30 |
31 | private void ComposeObjects()
32 | {
33 | Application.Current.MainWindow = Container.Get();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/Converters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Windows.Data;
4 | using System.Windows.Media;
5 |
6 | namespace PeopleViewer.Ninject
7 | {
8 | public class DecadeConverter : IValueConverter
9 | {
10 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
11 | {
12 | int year = ((DateTime)value).Year;
13 | return string.Format("{0}0s", year.ToString().Substring(0, 3));
14 | }
15 |
16 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
17 | {
18 | throw new NotImplementedException();
19 | }
20 | }
21 |
22 | public class RatingConverter : IValueConverter
23 | {
24 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
25 | {
26 | int rating = (int)value;
27 | return string.Format("{0}/10 Stars", rating.ToString());
28 | }
29 |
30 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
31 | {
32 | throw new NotImplementedException();
33 | }
34 | }
35 |
36 | public class RatingStarConverter : IValueConverter
37 | {
38 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
39 | {
40 | int rating = (int)value;
41 | string output = string.Empty;
42 | return output.PadLeft(rating, '*');
43 | }
44 |
45 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
46 | {
47 | string input = (string)value;
48 | //int rating = 0;
49 |
50 | //foreach (var ch in input)
51 | // if (ch == '*')
52 | // rating++;
53 |
54 | //return rating;
55 |
56 | return input.Count(c => c == '*');
57 | }
58 | }
59 |
60 | public class DecadeBrushConverter : IValueConverter
61 | {
62 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
63 | {
64 | int decade = (((DateTime)value).Year / 10) * 10;
65 |
66 | switch (decade)
67 | {
68 | case 1970:
69 | return new SolidColorBrush(Colors.Maroon);
70 | case 1980:
71 | return new SolidColorBrush(Colors.DarkGreen);
72 | case 1990:
73 | return new SolidColorBrush(Colors.DarkSlateBlue);
74 | case 2000:
75 | return new SolidColorBrush(Colors.CadetBlue);
76 | default:
77 | return new SolidColorBrush(Colors.DarkSlateGray);
78 | }
79 | }
80 |
81 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
82 | {
83 | throw new NotImplementedException();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
39 |
40 |
41 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using PeopleViewer.Presentation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace PeopleViewer.Ninject
18 | {
19 | public partial class MainWindow : Window
20 | {
21 | PeopleViewModel ViewModel { get; set; }
22 |
23 | public MainWindow(PeopleViewModel viewModel)
24 | {
25 | InitializeComponent();
26 | ViewModel = viewModel;
27 | DataContext = ViewModel;
28 | }
29 |
30 | private void RefreshButton_Click(object sender, RoutedEventArgs e)
31 | {
32 | ViewModel.RefreshPeople();
33 | }
34 |
35 | private void ClearButton_Click(object sender, RoutedEventArgs e)
36 | {
37 | ViewModel.ClearPeople();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/PeopleViewer.Ninject.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PackageReference
6 | Debug
7 | AnyCPU
8 | {A8F28521-413D-4E59-82AD-24C6D2B1DA4B}
9 | WinExe
10 | PeopleViewer.Ninject
11 | PeopleViewer.Ninject
12 | v4.7
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 | App.xaml
64 | Code
65 |
66 |
67 |
68 | MainWindow.xaml
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | True
78 | True
79 | Resources.resx
80 |
81 |
82 | True
83 | Settings.settings
84 | True
85 |
86 |
87 | ResXFileCodeGenerator
88 | Resources.Designer.cs
89 |
90 |
91 |
92 | SettingsSingleFileGenerator
93 | Settings.Designer.cs
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | {1b82b92c-6693-4922-ae9a-9cacb5c4e24f}
102 | Common
103 |
104 |
105 | {12581640-1ecc-44d0-9a6b-66b28fffe65f}
106 | PeopleViewer.Presentation
107 |
108 |
109 | {1a21a62f-0a90-4f94-88aa-341c730f54a7}
110 | PersonRepository.Caching
111 |
112 |
113 | {1174395b-80cf-4109-b049-e6f041c4b9a9}
114 | PersonRepository.CSV
115 |
116 |
117 | {f0db1627-f716-44af-b545-e4a649edd771}
118 | PersonRepository.Service
119 |
120 |
121 |
122 |
123 | 13.0.1
124 |
125 |
126 | 3.3.4
127 |
128 |
129 |
130 |
131 | xcopy "$(SolutionDir)AdditionalFiles\*.*" "$(TargetDir)" /Y
132 |
133 |
134 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeopleViewer.Ninject")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeopleViewer.Ninject")]
15 | [assembly: AssemblyCopyright("Copyright © 2018")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Ninject.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeopleViewer.Ninject.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Ninject.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Ninject/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation.Tests/FakeRepository.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace PeopleViewer.Presentation.Tests
8 | {
9 | public class FakeRepository : IPersonRepository
10 | {
11 |
12 | public IEnumerable GetPeople()
13 | {
14 | var people = new List()
15 | {
16 | new Person() {Id = 1,
17 | GivenName = "John", FamilyName = "Smith",
18 | Rating = 7, StartDate = new DateTime(2000, 10, 1)},
19 | new Person() {Id = 2,
20 | GivenName = "Mary", FamilyName = "Thomas",
21 | Rating = 9, StartDate = new DateTime(1971, 7, 23)},
22 | };
23 |
24 | return people;
25 | }
26 |
27 | public Person GetPerson(int id)
28 | {
29 | var people = GetPeople();
30 | return people.FirstOrDefault(p => p.Id == id);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation.Tests/PeopleViewModelTests.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using NUnit.Framework;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace PeopleViewer.Presentation.Tests
7 | {
8 | public class PeopleViewModelTests
9 | {
10 | private IPersonRepository GetTestRepository()
11 | {
12 | return new FakeRepository();
13 | }
14 |
15 | [Test]
16 | public void RefreshPeople_OnExecute_PeopleIsPopulated()
17 | {
18 | // Arrange
19 | var repository = GetTestRepository();
20 | var vm = new PeopleViewModel(repository);
21 |
22 | // Act
23 | vm.RefreshPeople();
24 |
25 | // Assert
26 | Assert.IsNotNull(vm.People);
27 | Assert.AreEqual(2, vm.People.Count());
28 | }
29 |
30 | [Test]
31 | public void ClearPeople_OnExecute_PeopleIsEmpty()
32 | {
33 | // Arrange
34 | var repository = GetTestRepository();
35 | var vm = new PeopleViewModel(repository);
36 | vm.RefreshPeople();
37 | Assert.AreEqual(2, vm.People.Count(), "Invalid Arrangement");
38 |
39 | // Act
40 | vm.ClearPeople();
41 |
42 | // Assert
43 | Assert.AreEqual(0, vm.People.Count());
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation.Tests/PeopleViewer.Presentation.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Debug
8 | AnyCPU
9 | {8BB096F4-1DB0-4038-BA69-A4F75406D336}
10 | Library
11 | Properties
12 | PeopleViewer.Presentation.Tests
13 | PeopleViewer.Presentation.Tests
14 | v4.7
15 | 512
16 |
17 |
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 | ..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | {1b82b92c-6693-4922-ae9a-9cacb5c4e24f}
58 | Common
59 |
60 |
61 | {12581640-1ecc-44d0-9a6b-66b28fffe65f}
62 | PeopleViewer.Presentation
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("PeopleViewer.Presentation.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("PeopleViewer.Presentation.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("8bb096f4-1db0-4038-ba69-a4f75406d336")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation/PeopleViewModel.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 |
5 | namespace PeopleViewer.Presentation
6 | {
7 | public class PeopleViewModel : INotifyPropertyChanged
8 | {
9 | protected IPersonRepository Repository;
10 |
11 | private IEnumerable _people;
12 | public IEnumerable People
13 | {
14 | get { return _people; }
15 | set
16 | {
17 | if (_people == value)
18 | return;
19 | _people = value;
20 | RaisePropertyChanged("People");
21 | }
22 | }
23 |
24 | public PeopleViewModel(IPersonRepository repository)
25 | {
26 | Repository = repository;
27 | }
28 |
29 | public void RefreshPeople()
30 | {
31 | People = Repository.GetPeople();
32 | }
33 |
34 | public void ClearPeople()
35 | {
36 | People = new List();
37 | }
38 |
39 | #region INotifyPropertyChanged Members
40 |
41 | public event PropertyChangedEventHandler PropertyChanged;
42 | private void RaisePropertyChanged(string propertyName)
43 | {
44 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
45 | }
46 |
47 | #endregion
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer.Presentation/PeopleViewer.Presentation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using PeopleViewer.Presentation;
2 | using PersonRepository.Caching;
3 | using PersonRepository.CSV;
4 | using PersonRepository.Service;
5 | using System.Windows;
6 |
7 | namespace PeopleViewer
8 | {
9 | public partial class App : Application
10 | {
11 | protected override void OnStartup(StartupEventArgs e)
12 | {
13 | base.OnStartup(e);
14 | ComposeObjects();
15 | Application.Current.MainWindow.Show();
16 | }
17 |
18 | private static void ComposeObjects()
19 | {
20 | var wrappeRepo = new ServiceRepository();
21 | var repository = new CachingRepository(wrappeRepo);
22 | var viewModel = new PeopleViewModel(repository);
23 | Application.Current.MainWindow = new MainWindow(viewModel);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/Converters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Windows.Data;
4 | using System.Windows.Media;
5 |
6 | namespace PeopleViewer
7 | {
8 | public class DecadeConverter : IValueConverter
9 | {
10 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
11 | {
12 | int year = ((DateTime)value).Year;
13 | return string.Format("{0}0s", year.ToString().Substring(0, 3));
14 | }
15 |
16 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
17 | {
18 | throw new NotImplementedException();
19 | }
20 | }
21 |
22 | public class RatingConverter : IValueConverter
23 | {
24 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
25 | {
26 | int rating = (int)value;
27 | return string.Format("{0}/10 Stars", rating.ToString());
28 | }
29 |
30 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
31 | {
32 | throw new NotImplementedException();
33 | }
34 | }
35 |
36 | public class RatingStarConverter : IValueConverter
37 | {
38 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
39 | {
40 | int rating = (int)value;
41 | string output = string.Empty;
42 | return output.PadLeft(rating, '*');
43 | }
44 |
45 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
46 | {
47 | string input = (string)value;
48 | //int rating = 0;
49 |
50 | //foreach (var ch in input)
51 | // if (ch == '*')
52 | // rating++;
53 |
54 | //return rating;
55 |
56 | return input.Count(c => c == '*');
57 | }
58 | }
59 |
60 | public class DecadeBrushConverter : IValueConverter
61 | {
62 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
63 | {
64 | int decade = (((DateTime)value).Year / 10) * 10;
65 |
66 | switch (decade)
67 | {
68 | case 1970:
69 | return new SolidColorBrush(Colors.Maroon);
70 | case 1980:
71 | return new SolidColorBrush(Colors.DarkGreen);
72 | case 1990:
73 | return new SolidColorBrush(Colors.DarkSlateBlue);
74 | case 2000:
75 | return new SolidColorBrush(Colors.CadetBlue);
76 | default:
77 | return new SolidColorBrush(Colors.DarkSlateGray);
78 | }
79 | }
80 |
81 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
82 | {
83 | throw new NotImplementedException();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
39 |
40 |
41 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using PeopleViewer.Presentation;
2 | using System.Windows;
3 |
4 | namespace PeopleViewer
5 | {
6 | public partial class MainWindow : Window
7 | {
8 | PeopleViewModel ViewModel { get; set; }
9 |
10 | public MainWindow(PeopleViewModel viewModel)
11 | {
12 | InitializeComponent();
13 | ViewModel = viewModel;
14 | DataContext = ViewModel;
15 | }
16 |
17 | private void RefreshButton_Click(object sender, RoutedEventArgs e)
18 | {
19 | ViewModel.RefreshPeople();
20 | }
21 |
22 | private void ClearButton_Click(object sender, RoutedEventArgs e)
23 | {
24 | ViewModel.ClearPeople();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/PeopleViewer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PackageReference
6 | Debug
7 | AnyCPU
8 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}
9 | WinExe
10 | PeopleViewer
11 | PeopleViewer
12 | v4.7
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 | ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 4.0
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | MSBuild:Compile
59 | Designer
60 |
61 |
62 | MSBuild:Compile
63 | Designer
64 |
65 |
66 | App.xaml
67 | Code
68 |
69 |
70 |
71 | MainWindow.xaml
72 | Code
73 |
74 |
75 |
76 |
77 | Code
78 |
79 |
80 | True
81 | True
82 | Resources.resx
83 |
84 |
85 | True
86 | Settings.settings
87 | True
88 |
89 |
90 | ResXFileCodeGenerator
91 | Resources.Designer.cs
92 |
93 |
94 |
95 | SettingsSingleFileGenerator
96 | Settings.Designer.cs
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | {1b82b92c-6693-4922-ae9a-9cacb5c4e24f}
105 | Common
106 |
107 |
108 | {12581640-1ecc-44d0-9a6b-66b28fffe65f}
109 | PeopleViewer.Presentation
110 |
111 |
112 | {1a21a62f-0a90-4f94-88aa-341c730f54a7}
113 | PersonRepository.Caching
114 |
115 |
116 | {1174395b-80cf-4109-b049-e6f041c4b9a9}
117 | PersonRepository.CSV
118 |
119 |
120 | {f0db1627-f716-44af-b545-e4a649edd771}
121 | PersonRepository.Service
122 |
123 |
124 |
125 |
126 | xcopy "$(SolutionDir)AdditionalFiles\*.*" "$(TargetDir)" /Y
127 |
128 |
129 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeopleViewer")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeopleViewer")]
15 | [assembly: AssemblyCopyright("Copyright © 2018")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeopleViewer.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LooseCoupling/PeopleViewer/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV.Tests/CSVRepositoryTests.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using System;
3 | using System.IO;
4 | using System.Linq;
5 |
6 | namespace PersonRepository.CSV.Tests
7 | {
8 | public class CSVRepositoryTests
9 | {
10 | [Test]
11 | public void GetPeople_WithEmptyFile_ReturnsEmptyList()
12 | {
13 | var repository = new CSVRepository();
14 | repository.FileLoader = new FakeFileLoader("Empty");
15 |
16 | var result = repository.GetPeople();
17 |
18 | Assert.IsEmpty(result);
19 | }
20 |
21 | [Test]
22 | public void GetTask_WithNoFile_ThrowsFileNotFoundException()
23 | {
24 | var repository = new CSVRepository();
25 |
26 | try
27 | {
28 | var result = repository.GetPeople();
29 | Assert.Fail();
30 | }
31 | catch (FileNotFoundException)
32 | {
33 | Assert.Pass();
34 | }
35 | }
36 |
37 | [Test]
38 | public void GetPeople_WithGoodRecords_ReturnsGoodRecords()
39 | {
40 | var repository = new CSVRepository();
41 | repository.FileLoader = new FakeFileLoader("Good");
42 |
43 | var result = repository.GetPeople();
44 |
45 | Assert.AreEqual(2, result.Count());
46 | }
47 |
48 | [Test]
49 | public void GetPeople_WithBadRecords_ReturnsGoodRecords()
50 | {
51 | var repository = new CSVRepository();
52 | repository.FileLoader = new FakeFileLoader("Mixed");
53 |
54 | var result = repository.GetPeople();
55 |
56 | Assert.AreEqual(2, result.Count());
57 | }
58 |
59 | [Test]
60 | public void GetPeople_WithOnlyBadRecord_ReturnsEmptyList()
61 | {
62 | var repository = new CSVRepository();
63 | repository.FileLoader = new FakeFileLoader("Bad");
64 |
65 | var result = repository.GetPeople();
66 |
67 | Assert.IsEmpty(result);
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV.Tests/FakeFileLoader.cs:
--------------------------------------------------------------------------------
1 | namespace PersonRepository.CSV.Tests
2 | {
3 | public class FakeFileLoader : ICSVFileLoader
4 | {
5 | private string dataType;
6 |
7 | public FakeFileLoader(string dataType)
8 | {
9 | this.dataType = dataType;
10 | }
11 |
12 | public string LoadFile()
13 | {
14 | switch (dataType)
15 | {
16 | case "Good": return TestData.WithGoodRecords;
17 | case "Mixed": return TestData.WithGoodAndBadRecords;
18 | case "Bad": return TestData.WithOnlyBadRecords;
19 | case "Empty": return string.Empty;
20 | default: return TestData.WithGoodRecords;
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV.Tests/PersonRepository.CSV.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Debug
8 | AnyCPU
9 | {CB1BFAB0-7133-44B2-83B3-1E0C3637E6CE}
10 | Library
11 | Properties
12 | PersonRepository.CSV.Tests
13 | PersonRepository.CSV.Tests
14 | v4.7
15 | 512
16 |
17 |
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 | ..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | {1b82b92c-6693-4922-ae9a-9cacb5c4e24f}
58 | Common
59 |
60 |
61 | {1174395b-80cf-4109-b049-e6f041c4b9a9}
62 | PersonRepository.CSV
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
72 |
73 |
74 |
75 |
76 |
77 | xcopy "$(SolutionDir)AdditionalFiles\People.txt" "$(TargetDir)TestData\" /Y
78 |
79 |
80 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("PersonRepository.CSV.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("PersonRepository.CSV.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("cb1bfab0-7133-44b2-83b3-1e0c3637e6ce")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV.Tests/TestData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace PersonRepository.CSV.Tests
4 | {
5 | public static class TestData
6 | {
7 | public static string WithGoodRecords =
8 | "1,John,Koenig,1975/10/17,6," + Environment.NewLine +
9 | "3,Leela,Turanga,1999/3/28,8,{1} {0}" + Environment.NewLine;
10 |
11 | public static string WithGoodAndBadRecords =
12 | "1,John,Koenig,1975/10/17,6," + Environment.NewLine +
13 | "INVALID DATA" + Environment.NewLine +
14 | "3,Leela,Turanga,1999/3/28,8,{1} {0}" + Environment.NewLine +
15 | "MORE INVALID DATA" + Environment.NewLine;
16 |
17 | public static string WithOnlyBadRecords =
18 | "INVALID DATA" + Environment.NewLine +
19 | "MORE INVALID DATA" + Environment.NewLine;
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV/CSVFileLoader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace PersonRepository.CSV
7 | {
8 | public interface ICSVFileLoader
9 | {
10 | string LoadFile();
11 | }
12 |
13 | public class CSVFileLoader : ICSVFileLoader
14 | {
15 | private string filePath;
16 |
17 | public CSVFileLoader(string filePath)
18 | {
19 | this.filePath = filePath;
20 | }
21 |
22 | public string LoadFile()
23 | {
24 | using (var reader = new StreamReader(filePath))
25 | {
26 | string fileData = reader.ReadToEnd();
27 | return fileData;
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV/CSVRepository.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace PersonRepository.CSV
7 | {
8 | public class CSVRepository : IPersonRepository
9 | {
10 | public ICSVFileLoader FileLoader { get; set; }
11 |
12 | public CSVRepository()
13 | {
14 | string filePath = AppDomain.CurrentDomain.BaseDirectory + "People.txt";
15 | FileLoader = new CSVFileLoader(filePath);
16 | }
17 |
18 | public IEnumerable GetPeople()
19 | {
20 | var fileData = FileLoader.LoadFile();
21 | var people = ParseString(fileData);
22 | return people;
23 | }
24 |
25 | public Person GetPerson(int id)
26 | {
27 | var people = GetPeople();
28 | return people?.FirstOrDefault(p => p.Id == id);
29 | }
30 |
31 | private List ParseString(string csvData)
32 | {
33 | var people = new List();
34 |
35 | var lines = csvData.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
36 |
37 | foreach (string line in lines)
38 | {
39 | try
40 | {
41 | var elems = line.Split(',');
42 | var per = new Person()
43 | {
44 | Id = Int32.Parse(elems[0]),
45 | GivenName = elems[1],
46 | FamilyName = elems[2],
47 | StartDate = DateTime.Parse(elems[3]),
48 | Rating = Int32.Parse(elems[4]),
49 | FormatString = elems[5],
50 | };
51 | people.Add(per);
52 | }
53 | catch (Exception)
54 | {
55 | // Skip the bad record, log it, and move to the next record
56 | // log.write("Unable to parse record", per);
57 | }
58 | }
59 | return people;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.CSV/PersonRepository.CSV.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.Caching/CachingRepository.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Threading.Tasks;
5 | using System.Linq;
6 |
7 | namespace PersonRepository.Caching
8 | {
9 | public class CachingRepository : IPersonRepository
10 | {
11 | private TimeSpan _cacheDuration = new TimeSpan(0, 0, 30);
12 | private DateTime _dataDateTime;
13 | private IPersonRepository _wrappedRepository;
14 | private IEnumerable _cachedItems;
15 |
16 | public CachingRepository(IPersonRepository wrappedPersonRepository)
17 | {
18 | _wrappedRepository = wrappedPersonRepository;
19 | }
20 |
21 | private bool IsCacheValid
22 | {
23 | get
24 | {
25 | var _cacheAge = DateTime.Now - _dataDateTime;
26 | return _cacheAge < _cacheDuration;
27 | }
28 | }
29 |
30 | private void ValidateCache()
31 | {
32 | if (_cachedItems == null || !IsCacheValid)
33 | {
34 | try
35 | {
36 | _cachedItems = _wrappedRepository.GetPeople();
37 | _dataDateTime = DateTime.Now;
38 | }
39 | catch
40 | {
41 | _cachedItems = new List()
42 | {
43 | new Person(){ GivenName = "No Data Available", FamilyName = string.Empty, Rating = 0, StartDate = DateTime.Today},
44 | };
45 | }
46 | }
47 | }
48 |
49 | private void InvalidateCache()
50 | {
51 | _dataDateTime = DateTime.MinValue;
52 | }
53 |
54 | public IEnumerable GetPeople()
55 | {
56 | ValidateCache();
57 | return _cachedItems;
58 | }
59 |
60 | public Person GetPerson(int id)
61 | {
62 | ValidateCache();
63 | return _cachedItems.FirstOrDefault(p => p.Id == id);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.Caching/PersonRepository.Caching.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.Service/PersonRepository.Service.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/LooseCoupling/PersonRepository.Service/ServiceRepository.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using Newtonsoft.Json;
3 | using System.Collections.Generic;
4 | using System.Net;
5 |
6 | namespace PersonRepository.Service
7 | {
8 | public class ServiceRepository : IPersonRepository
9 | {
10 | WebClient client;
11 | string baseUri;
12 |
13 | public ServiceRepository()
14 | {
15 | client = new WebClient();
16 | baseUri = "http://localhost:9874/";
17 | }
18 |
19 | public IEnumerable GetPeople()
20 | {
21 | var address = $"{baseUri}api/people";
22 | string reply = client.DownloadString(address);
23 | return JsonConvert.DeserializeObject>(reply);
24 | }
25 |
26 | public Person GetPerson(int id)
27 | {
28 | var address = $"{baseUri}api/people/{id}";
29 | string reply = client.DownloadString(address);
30 | return JsonConvert.DeserializeObject(reply);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | learning-dependency-injection
2 | =============================
3 |
4 | Many of our modern frameworks have Dependency Injection (DI) built in. But how do we use that effectively? We'll look at what DI is and why we want to use it. We'll see the problems caused by tight coupling. Then we'll use some DI patterns such as constructor injection and property injection to break that tight coupling. We'll see how loosely-coupled applications are easier to extend and test. With a better understanding of the basic patterns, we'll remove the magic behind DI containers so that we can use the tools appropriately in our code.
5 |
6 | Articles discribing the code are collected here: http://www.jeremybytes.com/Demos.aspx#DI
7 |
--------------------------------------------------------------------------------
/SLIDES-DependencyInjection.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeremybytes/learning-dependency-injection/116f6fb26ee661b8055808229aeba3ccfaff7b49/SLIDES-DependencyInjection.pdf
--------------------------------------------------------------------------------
/TightCoupling/Common/Common.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/TightCoupling/Common/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Common
4 | {
5 | public class Person
6 | {
7 | public int Id { get; set; }
8 | public string GivenName { get; set; }
9 | public string FamilyName { get; set; }
10 | public DateTime StartDate { get; set; }
11 | public int Rating { get; set; }
12 | public string FormatString { get; set; }
13 |
14 | public override string ToString()
15 | {
16 | if (string.IsNullOrEmpty(FormatString))
17 | FormatString = "{0} {1}";
18 | return string.Format(FormatString, GivenName, FamilyName);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/Controllers/PeopleController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Microsoft.AspNetCore.Mvc;
4 | using People.Service.Models;
5 | using Common;
6 |
7 | namespace People.Service.Controllers
8 | {
9 | [Route("api/[controller]")]
10 | [ApiController]
11 | public class PeopleController : ControllerBase
12 | {
13 | IPeopleProvider provider;
14 |
15 | public PeopleController(IPeopleProvider provider)
16 | {
17 | this.provider = provider;
18 | }
19 |
20 | // GET api/values
21 | [HttpGet]
22 | public IEnumerable Get()
23 | {
24 | return provider.GetPeople();
25 | }
26 |
27 | // GET api/values/5
28 | [HttpGet("{id}")]
29 | public Person Get(int id)
30 | {
31 | return provider.GetPeople().FirstOrDefault(p => p.Id == id);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/TightCoupling/People.Service/Models/IPeopleProvider.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System.Collections.Generic;
3 |
4 | namespace People.Service.Models
5 | {
6 | public interface IPeopleProvider
7 | {
8 | List GetPeople();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/Models/StaticPeopleProvider.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace People.Service.Models
6 | {
7 | public class StaticPeopleProvider : IPeopleProvider
8 | {
9 | public List GetPeople()
10 | {
11 | var p = new List()
12 | {
13 | new Person() { Id=1, GivenName="John", FamilyName="Koenig",
14 | StartDate = new DateTime(1975, 10, 17), Rating=6 },
15 | new Person() { Id=2, GivenName="Dylan", FamilyName="Hunt",
16 | StartDate = new DateTime(2000, 10, 2), Rating=8 },
17 | new Person() { Id=3, GivenName="Leela", FamilyName="Turanga",
18 | StartDate = new DateTime(1999, 3, 28), Rating=8,
19 | FormatString = "{1} {0}" },
20 | new Person() { Id=4, GivenName="John", FamilyName="Crichton",
21 | StartDate = new DateTime(1999, 3, 19), Rating=7 },
22 | new Person() { Id=5, GivenName="Dave", FamilyName="Lister",
23 | StartDate = new DateTime(1988, 2, 15), Rating=9 },
24 | new Person() { Id=6, GivenName="Laura", FamilyName="Roslin",
25 | StartDate = new DateTime(2003, 12, 8), Rating=6},
26 | new Person() { Id=7, GivenName="John", FamilyName="Sheridan",
27 | StartDate = new DateTime(1994, 1, 26), Rating=6 },
28 | new Person() { Id=8, GivenName="Dante", FamilyName="Montana",
29 | StartDate = new DateTime(2000, 11, 1), Rating=5 },
30 | new Person() { Id=9, GivenName="Isaac", FamilyName="Gampu",
31 | StartDate = new DateTime(1977, 9, 10), Rating=4 },
32 | };
33 | return p;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/People.Service.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 | InProcess
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 |
4 | namespace People.Service
5 | {
6 | public class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | CreateWebHostBuilder(args).Build().Run();
11 | }
12 |
13 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
14 | WebHost.CreateDefaultBuilder(args)
15 | .UseStartup()
16 | .UseUrls("http://localhost:9874");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:32101",
8 | "sslPort": 44340
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "api/values",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "People.Service": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "api/values",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/TightCoupling/People.Service/Startup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Builder;
2 | using Microsoft.AspNetCore.Hosting;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.Extensions.Configuration;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using People.Service.Models;
7 |
8 | namespace People.Service
9 | {
10 | public class Startup
11 | {
12 | public Startup(IConfiguration configuration)
13 | {
14 | Configuration = configuration;
15 | }
16 |
17 | public IConfiguration Configuration { get; }
18 |
19 | // This method gets called by the runtime. Use this method to add services to the container.
20 | public void ConfigureServices(IServiceCollection services)
21 | {
22 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
23 | services.AddSingleton();
24 | }
25 |
26 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
27 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
28 | {
29 | if (env.IsDevelopment())
30 | {
31 | app.UseDeveloperExceptionPage();
32 | }
33 | app.UseMvc();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/TightCoupling/People.Service/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*"
8 | }
9 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer.Presentation/PeopleViewModel.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using PersonRepository.Service;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.ComponentModel;
6 | using System.Threading.Tasks;
7 |
8 | namespace PeopleViewer.Presentation
9 | {
10 | public class PeopleViewModel : INotifyPropertyChanged
11 | {
12 | protected ServiceRepository Repository;
13 |
14 | private IEnumerable _people;
15 | public IEnumerable People
16 | {
17 | get { return _people; }
18 | set
19 | {
20 | if (_people == value)
21 | return;
22 | _people = value;
23 | RaisePropertyChanged("People");
24 | }
25 | }
26 |
27 | public PeopleViewModel()
28 | {
29 | Repository = new ServiceRepository();
30 | }
31 |
32 | public void RefreshPeople()
33 | {
34 | People = Repository.GetPeople();
35 | }
36 |
37 | public void ClearPeople()
38 | {
39 | People = new List();
40 | }
41 |
42 | #region INotifyPropertyChanged Members
43 |
44 | public event PropertyChangedEventHandler PropertyChanged;
45 | private void RaisePropertyChanged(string propertyName)
46 | {
47 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
48 | }
49 |
50 | #endregion
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer.Presentation/PeopleViewer.Presentation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace PeopleViewer
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/Converters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Windows.Data;
4 | using System.Windows.Media;
5 |
6 | namespace PeopleViewer
7 | {
8 | public class DecadeConverter : IValueConverter
9 | {
10 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
11 | {
12 | int year = ((DateTime)value).Year;
13 | return string.Format("{0}0s", year.ToString().Substring(0, 3));
14 | }
15 |
16 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
17 | {
18 | throw new NotImplementedException();
19 | }
20 | }
21 |
22 | public class RatingConverter : IValueConverter
23 | {
24 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
25 | {
26 | int rating = (int)value;
27 | return string.Format("{0}/10 Stars", rating.ToString());
28 | }
29 |
30 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
31 | {
32 | throw new NotImplementedException();
33 | }
34 | }
35 |
36 | public class RatingStarConverter : IValueConverter
37 | {
38 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
39 | {
40 | int rating = (int)value;
41 | string output = string.Empty;
42 | return output.PadLeft(rating, '*');
43 | }
44 |
45 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
46 | {
47 | string input = (string)value;
48 | //int rating = 0;
49 |
50 | //foreach (var ch in input)
51 | // if (ch == '*')
52 | // rating++;
53 |
54 | //return rating;
55 |
56 | return input.Count(c => c == '*');
57 | }
58 | }
59 |
60 | public class DecadeBrushConverter : IValueConverter
61 | {
62 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
63 | {
64 | int decade = (((DateTime)value).Year / 10) * 10;
65 |
66 | switch (decade)
67 | {
68 | case 1970:
69 | return new SolidColorBrush(Colors.Maroon);
70 | case 1980:
71 | return new SolidColorBrush(Colors.DarkGreen);
72 | case 1990:
73 | return new SolidColorBrush(Colors.DarkSlateBlue);
74 | case 2000:
75 | return new SolidColorBrush(Colors.CadetBlue);
76 | default:
77 | return new SolidColorBrush(Colors.DarkSlateGray);
78 | }
79 | }
80 |
81 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
82 | {
83 | throw new NotImplementedException();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
39 |
40 |
41 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using PeopleViewer.Presentation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Data;
10 | using System.Windows.Documents;
11 | using System.Windows.Input;
12 | using System.Windows.Media;
13 | using System.Windows.Media.Imaging;
14 | using System.Windows.Navigation;
15 | using System.Windows.Shapes;
16 |
17 | namespace PeopleViewer
18 | {
19 | public partial class MainWindow : Window
20 | {
21 | PeopleViewModel ViewModel { get; set; }
22 |
23 | public MainWindow()
24 | {
25 | InitializeComponent();
26 | ViewModel = new PeopleViewModel();
27 | DataContext = ViewModel;
28 | }
29 |
30 | private void RefreshButton_Click(object sender, RoutedEventArgs e)
31 | {
32 | ViewModel.RefreshPeople();
33 | }
34 |
35 | private void ClearButton_Click(object sender, RoutedEventArgs e)
36 | {
37 | ViewModel.ClearPeople();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/PeopleViewer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}
8 | WinExe
9 | PeopleViewer
10 | PeopleViewer
11 | v4.7.2
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 | ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 4.0
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | MSBuild:Compile
59 | Designer
60 |
61 |
62 | MSBuild:Compile
63 | Designer
64 |
65 |
66 | App.xaml
67 | Code
68 |
69 |
70 |
71 | MainWindow.xaml
72 | Code
73 |
74 |
75 |
76 |
77 | Code
78 |
79 |
80 | True
81 | True
82 | Resources.resx
83 |
84 |
85 | True
86 | Settings.settings
87 | True
88 |
89 |
90 | ResXFileCodeGenerator
91 | Resources.Designer.cs
92 |
93 |
94 |
95 | SettingsSingleFileGenerator
96 | Settings.Designer.cs
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | {12581640-1ecc-44d0-9a6b-66b28fffe65f}
105 | PeopleViewer.Presentation
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("PeopleViewer")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("PeopleViewer")]
15 | [assembly: AssemblyCopyright("Copyright © 2018")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PeopleViewer.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace PeopleViewer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/TightCoupling/PeopleViewer/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/TightCoupling/PersonRepository.Service/PersonRepository.Service.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/TightCoupling/PersonRepository.Service/ServiceRepository.cs:
--------------------------------------------------------------------------------
1 | using Common;
2 | using Newtonsoft.Json;
3 | using System.Collections.Generic;
4 | using System.Net;
5 |
6 | namespace PersonRepository.Service
7 | {
8 | public class ServiceRepository
9 | {
10 | private WebClient client;
11 | private string baseUri;
12 |
13 | public ServiceRepository()
14 | {
15 | client = new WebClient();
16 | baseUri = "http://localhost:9874/";
17 | }
18 |
19 | public IEnumerable GetPeople()
20 | {
21 | var address = $"{baseUri}api/people";
22 | string reply = client.DownloadString(address);
23 | return JsonConvert.DeserializeObject>(reply);
24 | }
25 |
26 | public Person GetPerson(int id)
27 | {
28 | var address = $"{baseUri}api/people/{id}";
29 | string reply = client.DownloadString(address);
30 | return JsonConvert.DeserializeObject(reply);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/TightCoupling/TightCoupling.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29123.88
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{1B82B92C-6693-4922-AE9A-9CACB5C4E24F}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "People.Service", "People.Service\People.Service.csproj", "{7CA7ABCC-8065-423F-964E-0135D83ADB02}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{817DFB31-DAED-403F-9FAD-312AF1E2CE89}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04-Data Storage", "04-Data Storage", "{7C50B4E7-1FB5-45B6-8AB3-5C0409109CB3}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeopleViewer", "PeopleViewer\PeopleViewer.csproj", "{E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01-Application View", "01-Application View", "{DB58D260-0DDF-45D3-9A65-9D0464733819}"
17 | EndProject
18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-Presentation", "02-Presentation", "{E46C5347-AEE9-4C96-96BC-F1B0C549A01C}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeopleViewer.Presentation", "PeopleViewer.Presentation\PeopleViewer.Presentation.csproj", "{12581640-1ECC-44D0-9A6B-66B28FFFE65F}"
21 | EndProject
22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03-Data Access", "03-Data Access", "{A7B96D7E-CCC5-42B8-964F-D87FE42B0074}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PersonRepository.Service", "PersonRepository.Service\PersonRepository.Service.csproj", "{F0DB1627-F716-44AF-B545-E4A649EDD771}"
25 | EndProject
26 | Global
27 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
28 | Debug|Any CPU = Debug|Any CPU
29 | Release|Any CPU = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
32 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {7CA7ABCC-8065-423F-964E-0135D83ADB02}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {F0DB1627-F716-44AF-B545-E4A649EDD771}.Release|Any CPU.Build.0 = Release|Any CPU
52 | EndGlobalSection
53 | GlobalSection(SolutionProperties) = preSolution
54 | HideSolutionNode = FALSE
55 | EndGlobalSection
56 | GlobalSection(NestedProjects) = preSolution
57 | {1B82B92C-6693-4922-AE9A-9CACB5C4E24F} = {817DFB31-DAED-403F-9FAD-312AF1E2CE89}
58 | {7CA7ABCC-8065-423F-964E-0135D83ADB02} = {7C50B4E7-1FB5-45B6-8AB3-5C0409109CB3}
59 | {E3FC00AA-A9E7-4E6F-9DDC-5E7C1D21E53A} = {DB58D260-0DDF-45D3-9A65-9D0464733819}
60 | {12581640-1ECC-44D0-9A6B-66B28FFFE65F} = {E46C5347-AEE9-4C96-96BC-F1B0C549A01C}
61 | {F0DB1627-F716-44AF-B545-E4A649EDD771} = {A7B96D7E-CCC5-42B8-964F-D87FE42B0074}
62 | EndGlobalSection
63 | GlobalSection(ExtensibilityGlobals) = postSolution
64 | SolutionGuid = {62280A51-57F7-4AEB-B108-3A00B1574DEA}
65 | EndGlobalSection
66 | EndGlobal
67 |
--------------------------------------------------------------------------------