├── .gitignore ├── FactoryPattern ├── FactoryPattern.Core │ ├── AbstractFactory.cs │ ├── BaseRepository.cs │ ├── FactoryPattern.Core.csproj │ ├── PermissionRepository.cs │ ├── RoleRepository.cs │ └── UserRepository.cs ├── FactoryPattern.Repository.EFCore │ ├── EFCoreRepositoryFactory.cs │ ├── FactoryPattern.Repository.EFCore.csproj │ ├── PermissionRepositoryEFCore.cs │ ├── RoleRepositoryEFCore.cs │ └── UserRepositoryEFCore.cs ├── FactoryPattern.Repository.Sugar │ ├── FactoryPattern.Repository.Sugar.csproj │ ├── PermissionRepositorySugar.cs │ ├── RoleRepositorySugar.cs │ ├── SugarRepositoryFactory.cs │ └── UserRepositorySugar.cs ├── FactoryPattern.sln ├── FactoryPattern │ ├── Controllers │ │ └── WeatherForecastController.cs │ ├── FactoryPattern.csproj │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── WeatherForecast.cs │ ├── appsettings.Development.json │ └── appsettings.json └── README.md ├── LICENSE ├── README.md └── SingletonPattern ├── README.md ├── SingletonPattern.sln └── SingletonPattern ├── Controllers └── WeatherForecastController.cs ├── Feeling.cs ├── Program.cs ├── Properties └── launchSettings.json ├── SingletonPattern.csproj ├── Startup.cs ├── WeatherForecast.cs ├── appsettings.Development.json └── appsettings.json /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | # ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true 235 | **/wwwroot/lib/ 236 | 237 | # RIA/Silverlight projects 238 | Generated_Code/ 239 | 240 | # Backup & report files from converting an old project file 241 | # to a newer Visual Studio version. Backup files are not needed, 242 | # because we have git ;-) 243 | _UpgradeReport_Files/ 244 | Backup*/ 245 | UpgradeLog*.XML 246 | UpgradeLog*.htm 247 | ServiceFabricBackup/ 248 | *.rptproj.bak 249 | 250 | # SQL Server files 251 | *.mdf 252 | *.ldf 253 | *.ndf 254 | 255 | # Business Intelligence projects 256 | *.rdl.data 257 | *.bim.layout 258 | *.bim_*.settings 259 | *.rptproj.rsuser 260 | 261 | # Microsoft Fakes 262 | FakesAssemblies/ 263 | 264 | # GhostDoc plugin setting file 265 | *.GhostDoc.xml 266 | 267 | # Node.js Tools for Visual Studio 268 | .ntvs_analysis.dat 269 | node_modules/ 270 | 271 | # Visual Studio 6 build log 272 | *.plg 273 | 274 | # Visual Studio 6 workspace options file 275 | *.opt 276 | 277 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 278 | *.vbw 279 | 280 | # Visual Studio LightSwitch build output 281 | **/*.HTMLClient/GeneratedArtifacts 282 | **/*.DesktopClient/GeneratedArtifacts 283 | **/*.DesktopClient/ModelManifest.xml 284 | **/*.Server/GeneratedArtifacts 285 | **/*.Server/ModelManifest.xml 286 | _Pvt_Extensions 287 | 288 | # Paket dependency manager 289 | .paket/paket.exe 290 | paket-files/ 291 | 292 | # FAKE - F# Make 293 | .fake/ 294 | 295 | # JetBrains Rider 296 | .idea/ 297 | *.sln.iml 298 | 299 | # CodeRush personal settings 300 | .cr/personal 301 | 302 | # Python Tools for Visual Studio (PTVS) 303 | __pycache__/ 304 | *.pyc 305 | 306 | # Cake - Uncomment if you are using it 307 | # tools/** 308 | # !tools/packages.config 309 | 310 | # Tabs Studio 311 | *.tss 312 | 313 | # Telerik's JustMock configuration file 314 | *.jmconfig 315 | 316 | # BizTalk build output 317 | *.btp.cs 318 | *.btm.cs 319 | *.odx.cs 320 | *.xsd.cs 321 | 322 | # OpenCover UI analysis results 323 | OpenCover/ 324 | 325 | # Azure Stream Analytics local run output 326 | ASALocalRun/ 327 | 328 | # MSBuild Binary and Structured Log 329 | *.binlog 330 | 331 | # NVidia Nsight GPU debugger configuration file 332 | *.nvuser 333 | 334 | # MFractors (Xamarin productivity tool) working folder 335 | .mfractor/ 336 | 337 | # Local History for Visual Studio 338 | .localhistory/ 339 | 340 | # BeatPulse healthcheck temp database 341 | healthchecksdb 342 | 343 | 344 | # wwwroot/images 345 | *images/ 346 | !Blog.Core/WMBlog.db 347 | .1YourProject 348 | .PublishFiles 349 | !.template.config/*.nupkg 350 | !Blog.Core.Webapi.Template.*.nupkg 351 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Core/AbstractFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace FactoryPattern.Core 4 | { 5 | /// 6 | /// 抽象工厂类,提供创建不同仓储接口 7 | /// 8 | public abstract class AbstractFactory 9 | { 10 | // 抽象工厂提供创建一系列产品的接口 11 | public abstract UserRepository UserRepository(); 12 | public abstract RoleRepository RoleRepository(); 13 | public abstract PermissionRepository PermissionRepository(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Core/BaseRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace FactoryPattern.Core 6 | { 7 | /// 8 | /// 定义基类仓储 9 | /// 10 | public abstract class BaseRepository 11 | { 12 | /// 13 | /// 创建 14 | /// 15 | public abstract void Add(); 16 | /// 17 | /// 删除 18 | /// 19 | public abstract void Delete(); 20 | /// 21 | /// 修改 22 | /// 23 | public abstract void Update(); 24 | /// 25 | /// 查询 26 | /// / 27 | public abstract void Query(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Core/FactoryPattern.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Core/PermissionRepository.cs: -------------------------------------------------------------------------------- 1 | namespace FactoryPattern.Core 2 | { 3 | /// 4 | /// 同 UserRepository 5 | /// 6 | public abstract class PermissionRepository: BaseRepository 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Core/RoleRepository.cs: -------------------------------------------------------------------------------- 1 | namespace FactoryPattern.Core 2 | { 3 | /// 4 | /// 同 UserRepository 5 | /// 6 | public abstract class RoleRepository: BaseRepository 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Core/UserRepository.cs: -------------------------------------------------------------------------------- 1 | namespace FactoryPattern.Core 2 | { 3 | /// 4 | /// 定义抽象用户仓储,继承抽象基类仓储 5 | /// 抽象的目的,是为了给UserRepositoryEFCore、UserRepositorySugar、 6 | /// 做父类 7 | /// 8 | public abstract class UserRepository: BaseRepository 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.EFCore/EFCoreRepositoryFactory.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | 4 | namespace FactoryPattern.Repository.EFCore 5 | { 6 | /// 7 | /// EFCore 仓储子工厂 8 | /// 用来生产各个实体仓储 9 | /// 10 | public class EFCoreRepositoryFactory : AbstractFactory 11 | { 12 | public override PermissionRepository PermissionRepository() 13 | { 14 | return new PermissionRepositoryEFCore(); 15 | } 16 | 17 | public override RoleRepository RoleRepository() 18 | { 19 | return new RoleRepositoryEFCore(); 20 | } 21 | 22 | public override UserRepository UserRepository() 23 | { 24 | return new UserRepositoryEFCore(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.EFCore/FactoryPattern.Repository.EFCore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.EFCore/PermissionRepositoryEFCore.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace FactoryPattern.Repository.EFCore 7 | { 8 | public class PermissionRepositoryEFCore : PermissionRepository 9 | { 10 | public override void Add() 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override void Delete() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public override void Query() 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public override void Update() 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.EFCore/RoleRepositoryEFCore.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace FactoryPattern.Repository.EFCore 7 | { 8 | public class RoleRepositoryEFCore : RoleRepository 9 | { 10 | public override void Add() 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override void Delete() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public override void Query() 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public override void Update() 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.EFCore/UserRepositoryEFCore.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace FactoryPattern.Repository.EFCore 7 | { 8 | /// 9 | /// EFCore User 仓储,继承User仓储 10 | /// 11 | public class UserRepositoryEFCore : UserRepository 12 | { 13 | public override void Add() 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | 18 | public override void Delete() 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | 23 | public override void Query() 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | 28 | public override void Update() 29 | { 30 | throw new NotImplementedException(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.Sugar/FactoryPattern.Repository.Sugar.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.Sugar/PermissionRepositorySugar.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace FactoryPattern.Repository.Sugar 7 | { 8 | public class PermissionRepositorySugar : PermissionRepository 9 | { 10 | public override void Add() 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override void Delete() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public override void Query() 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public override void Update() 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.Sugar/RoleRepositorySugar.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace FactoryPattern.Repository.Sugar 7 | { 8 | public class RoleRepositorySugar : RoleRepository 9 | { 10 | public override void Add() 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | 15 | public override void Delete() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public override void Query() 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public override void Update() 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.Sugar/SugarRepositoryFactory.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | 4 | namespace FactoryPattern.Repository.Sugar 5 | { 6 | /// 7 | /// Sugar 仓储子工厂 8 | /// 用来生产各个实体仓储 9 | /// 10 | public class SugarRepositoryFactory : AbstractFactory 11 | { 12 | public override PermissionRepository PermissionRepository() 13 | { 14 | return new PermissionRepositorySugar(); 15 | } 16 | 17 | public override RoleRepository RoleRepository() 18 | { 19 | return new RoleRepositorySugar(); 20 | } 21 | 22 | public override UserRepository UserRepository() 23 | { 24 | return new UserRepositorySugar(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.Repository.Sugar/UserRepositorySugar.cs: -------------------------------------------------------------------------------- 1 | using FactoryPattern.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace FactoryPattern.Repository.Sugar 7 | { 8 | /// 9 | /// Sugar User 仓储,继承User仓储 10 | /// 11 | public class UserRepositorySugar : UserRepository 12 | { 13 | public override void Add() 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | 18 | public override void Delete() 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | 23 | public override void Query() 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | 28 | public override void Update() 29 | { 30 | throw new NotImplementedException(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29418.71 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern", "FactoryPattern\FactoryPattern.csproj", "{26F20419-8FF9-4188-85A2-DF2B4100F73B}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern.Core", "FactoryPattern.Core\FactoryPattern.Core.csproj", "{D8A71DCF-41D7-4225-9C87-912FFB108A81}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern.Repository.EFCore", "FactoryPattern.Repository.EFCore\FactoryPattern.Repository.EFCore.csproj", "{BB14C04F-202D-416B-8F70-50E6CF860576}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryPattern.Repository.Sugar", "FactoryPattern.Repository.Sugar\FactoryPattern.Repository.Sugar.csproj", "{014D345B-FD96-41C1-9977-E257F5359ECD}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {26F20419-8FF9-4188-85A2-DF2B4100F73B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {26F20419-8FF9-4188-85A2-DF2B4100F73B}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {26F20419-8FF9-4188-85A2-DF2B4100F73B}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {26F20419-8FF9-4188-85A2-DF2B4100F73B}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {D8A71DCF-41D7-4225-9C87-912FFB108A81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {D8A71DCF-41D7-4225-9C87-912FFB108A81}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {D8A71DCF-41D7-4225-9C87-912FFB108A81}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {D8A71DCF-41D7-4225-9C87-912FFB108A81}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {BB14C04F-202D-416B-8F70-50E6CF860576}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {BB14C04F-202D-416B-8F70-50E6CF860576}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {BB14C04F-202D-416B-8F70-50E6CF860576}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {BB14C04F-202D-416B-8F70-50E6CF860576}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {014D345B-FD96-41C1-9977-E257F5359ECD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {014D345B-FD96-41C1-9977-E257F5359ECD}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {014D345B-FD96-41C1-9977-E257F5359ECD}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {014D345B-FD96-41C1-9977-E257F5359ECD}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {4B7FC08A-0ACD-4CEA-8B91-8EA0F9CF836A} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using FactoryPattern.Core; 6 | using FactoryPattern.Repository.EFCore; 7 | using FactoryPattern.Repository.Sugar; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace FactoryPattern.Controllers 12 | { 13 | [ApiController] 14 | [Route("[controller]")] 15 | public class WeatherForecastController : ControllerBase 16 | { 17 | private static readonly string[] Summaries = new[] 18 | { 19 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 20 | }; 21 | 22 | private readonly ILogger _logger; 23 | 24 | public WeatherForecastController(ILogger logger) 25 | { 26 | _logger = logger; 27 | } 28 | 29 | [HttpGet] 30 | public void Get() 31 | { 32 | // 实例化工厂,这里用来生产 efcore 这一系列的 产品 33 | AbstractFactory efcoreFactory = new EFCoreRepositoryFactory(); 34 | efcoreFactory.UserRepository().Add(); 35 | efcoreFactory.RoleRepository().Delete(); 36 | efcoreFactory.PermissionRepository().Query(); 37 | 38 | 39 | // 实例化工厂,这里用来生产 sugar 这一系列的 产品 40 | AbstractFactory sugarFactory = new SugarRepositoryFactory(); 41 | sugarFactory.UserRepository().Add(); 42 | sugarFactory.RoleRepository().Delete(); 43 | sugarFactory.PermissionRepository().Query(); 44 | 45 | 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/FactoryPattern.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace FactoryPattern 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/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:52267", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "FactoryPattern": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Hosting; 11 | using Microsoft.Extensions.Logging; 12 | 13 | namespace FactoryPattern 14 | { 15 | public class Startup 16 | { 17 | public Startup(IConfiguration configuration) 18 | { 19 | Configuration = configuration; 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddControllers(); 28 | } 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseRouting(); 39 | 40 | app.UseAuthorization(); 41 | 42 | app.UseEndpoints(endpoints => 43 | { 44 | endpoints.MapControllers(); 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace FactoryPattern 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /FactoryPattern/FactoryPattern/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /FactoryPattern/README.md: -------------------------------------------------------------------------------- 1 | # DesignPattern 2 | 工厂模式:简单工厂、工厂方法、抽象工厂 3 | 4 | 5 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ansonzhang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DesignPattern 2 | 23种设计模式相关资料代码 3 | -------------------------------------------------------------------------------- /SingletonPattern/README.md: -------------------------------------------------------------------------------- 1 | # DesignPattern 2 | 单例模式 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29418.71 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingletonPattern", "SingletonPattern\SingletonPattern.csproj", "{B228456C-ED05-4326-89C4-7C79A55C497C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B228456C-ED05-4326-89C4-7C79A55C497C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B228456C-ED05-4326-89C4-7C79A55C497C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B228456C-ED05-4326-89C4-7C79A55C497C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B228456C-ED05-4326-89C4-7C79A55C497C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {9565D620-D858-42B8-91A0-DA5D307EEDB3} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace SingletonPattern.Controllers 10 | { 11 | [ApiController] 12 | [Route("[controller]")] 13 | public class WeatherForecastController : ControllerBase 14 | { 15 | private static readonly string[] Summaries = new[] 16 | { 17 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 18 | }; 19 | 20 | private readonly ILogger _logger; 21 | private readonly Feeling _feeling; 22 | 23 | public WeatherForecastController(ILogger logger, Feeling feeling) 24 | { 25 | _logger = logger; 26 | _feeling = feeling; 27 | } 28 | 29 | 30 | [HttpGet] 31 | public WeatherForecast Get() 32 | { 33 | // 实例化一个对象实例 34 | //WeatherForecast weather = WeatherForecast.GetInstance(); 35 | 36 | // 多线程去调用 37 | for (int i = 0; i < 3; i++) 38 | { 39 | var th = new Thread( 40 | new ParameterizedThreadStart((state) => 41 | { 42 | //WeatherForecast.GetInstance(); 43 | 44 | // 此刻的心情 45 | Console.WriteLine(_feeling.Date); 46 | }) 47 | ); 48 | th.Start(i); 49 | } 50 | return null; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/Feeling.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace SingletonPattern 7 | { 8 | /// 9 | /// 定义一个心情类 10 | /// 11 | public class Feeling 12 | { 13 | public Feeling() 14 | { 15 | Date = DateTime.Now; 16 | } 17 | public DateTime Date { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace SingletonPattern 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/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:50792", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "SingletonPattern": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/SingletonPattern.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/Startup.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anjoy8/DesignPattern/d6b8ffd9c436934be34050a0760fa6fbd19a4cfd/SingletonPattern/SingletonPattern/Startup.cs -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/WeatherForecast.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anjoy8/DesignPattern/d6b8ffd9c436934be34050a0760fa6fbd19a4cfd/SingletonPattern/SingletonPattern/WeatherForecast.cs -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /SingletonPattern/SingletonPattern/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | --------------------------------------------------------------------------------