├── .editorconfig ├── .gitignore ├── DomainModeling.sln ├── LICENSE ├── README.md └── src └── DomainModeling.Web ├── BaseEntity.cs ├── DomainModeling.Web.csproj ├── DomainModeling.Web.xml ├── Endpoints ├── Anemic │ ├── Complete.cs │ ├── Data.cs │ ├── GetById.cs │ ├── Project.cs │ ├── ToDoItem.cs │ ├── UpdateToDoItem.UpdateToDoItemRequest.cs │ └── UpdateToDoItem.cs ├── AnemicV2 │ ├── Complete.cs │ ├── Data.cs │ ├── GetById.cs │ ├── NotificationService.cs │ ├── Project.cs │ ├── ToDoItem.cs │ ├── UpdateToDoItem.UpdateToDoItemRequest.cs │ └── UpdateToDoItem.cs └── Encapsulated │ ├── Complete.cs │ ├── DataService.cs │ ├── DomainEventBase.cs │ ├── EntityBase.cs │ ├── GetById.cs │ ├── NotificationService.cs │ ├── Project.cs │ ├── ToDoItem.cs │ ├── UpdateToDoItem.UpdateToDoItemRequest.cs │ └── UpdateToDoItem.cs ├── Program.cs ├── Properties └── launchSettings.json ├── appsettings.Development.json └── appsettings.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # To learn more about .editorconfig see https://aka.ms/editorconfigdocs 2 | ############################### 3 | # Core EditorConfig Options # 4 | ############################### 5 | # All files 6 | [*] 7 | indent_style = space 8 | 9 | # XML project files 10 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 11 | indent_size = 2 12 | 13 | # XML config files 14 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 15 | indent_size = 2 16 | 17 | # Code files 18 | [*.{cs,csx,vb,vbx}] 19 | indent_size = 2 20 | insert_final_newline = true 21 | charset = utf-8-bom 22 | ############################### 23 | # .NET Coding Conventions # 24 | ############################### 25 | [*.{cs,vb}] 26 | # Organize usings 27 | dotnet_sort_system_directives_first = true 28 | # this. preferences 29 | dotnet_style_qualification_for_field = false:silent 30 | dotnet_style_qualification_for_property = false:silent 31 | dotnet_style_qualification_for_method = false:silent 32 | dotnet_style_qualification_for_event = false:silent 33 | # Language keywords vs BCL types preferences 34 | dotnet_style_predefined_type_for_locals_parameters_members = true:silent 35 | dotnet_style_predefined_type_for_member_access = true:silent 36 | # Parentheses preferences 37 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent 38 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent 39 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent 40 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent 41 | # Modifier preferences 42 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent 43 | dotnet_style_readonly_field = true:suggestion 44 | # Expression-level preferences 45 | dotnet_style_object_initializer = true:suggestion 46 | dotnet_style_collection_initializer = true:suggestion 47 | dotnet_style_explicit_tuple_names = true:suggestion 48 | dotnet_style_null_propagation = true:suggestion 49 | dotnet_style_coalesce_expression = true:suggestion 50 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent 51 | dotnet_style_prefer_inferred_tuple_names = true:suggestion 52 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 53 | dotnet_style_prefer_auto_properties = true:silent 54 | dotnet_style_prefer_conditional_expression_over_assignment = true:silent 55 | dotnet_style_prefer_conditional_expression_over_return = true:silent 56 | ############################### 57 | # Naming Conventions # 58 | ############################### 59 | # Style Definitions 60 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 61 | # Use PascalCase for constant fields 62 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion 63 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 64 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 65 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 66 | dotnet_naming_symbols.constant_fields.applicable_accessibilities = * 67 | dotnet_naming_symbols.constant_fields.required_modifiers = const 68 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 69 | tab_width = 2 70 | end_of_line = crlf 71 | dotnet_style_prefer_simplified_boolean_expressions = true:suggestion 72 | dotnet_style_prefer_compound_assignment = true:suggestion 73 | dotnet_style_prefer_simplified_interpolation = true:suggestion 74 | ############################### 75 | # C# Coding Conventions # 76 | ############################### 77 | [*.cs] 78 | # var preferences 79 | csharp_style_var_for_built_in_types = true:silent 80 | csharp_style_var_when_type_is_apparent = true:silent 81 | csharp_style_var_elsewhere = true:silent 82 | # Expression-bodied members 83 | csharp_style_expression_bodied_methods = false:silent 84 | csharp_style_expression_bodied_constructors = false:silent 85 | csharp_style_expression_bodied_operators = false:silent 86 | csharp_style_expression_bodied_properties = true:silent 87 | csharp_style_expression_bodied_indexers = true:silent 88 | csharp_style_expression_bodied_accessors = true:silent 89 | # Pattern matching preferences 90 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 91 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 92 | # Null-checking preferences 93 | csharp_style_throw_expression = true:suggestion 94 | csharp_style_conditional_delegate_call = true:suggestion 95 | # Modifier preferences 96 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion 97 | # Expression-level preferences 98 | csharp_prefer_braces = true:silent 99 | csharp_style_deconstructed_variable_declaration = true:suggestion 100 | csharp_prefer_simple_default_expression = true:suggestion 101 | csharp_style_pattern_local_over_anonymous_function = true:suggestion 102 | csharp_style_inlined_variable_declaration = true:suggestion 103 | ############################### 104 | # C# Formatting Rules # 105 | ############################### 106 | # New line preferences 107 | csharp_new_line_before_open_brace = all 108 | csharp_new_line_before_else = true 109 | csharp_new_line_before_catch = true 110 | csharp_new_line_before_finally = true 111 | csharp_new_line_before_members_in_object_initializers = true 112 | csharp_new_line_before_members_in_anonymous_types = true 113 | csharp_new_line_between_query_expression_clauses = true 114 | # Indentation preferences 115 | csharp_indent_case_contents = true 116 | csharp_indent_switch_labels = true 117 | csharp_indent_labels = flush_left 118 | # Space preferences 119 | csharp_space_after_cast = false 120 | csharp_space_after_keywords_in_control_flow_statements = true 121 | csharp_space_between_method_call_parameter_list_parentheses = false 122 | csharp_space_between_method_declaration_parameter_list_parentheses = false 123 | csharp_space_between_parentheses = false 124 | csharp_space_before_colon_in_inheritance_clause = true 125 | csharp_space_after_colon_in_inheritance_clause = true 126 | csharp_space_around_binary_operators = before_and_after 127 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 128 | csharp_space_between_method_call_name_and_opening_parenthesis = false 129 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 130 | # Wrapping preferences 131 | csharp_preserve_single_line_statements = true 132 | csharp_preserve_single_line_blocks = true 133 | csharp_using_directive_placement = outside_namespace:silent 134 | csharp_prefer_simple_using_statement = true:suggestion 135 | csharp_style_namespace_declarations = block_scoped:silent 136 | csharp_style_prefer_method_group_conversion = true:silent 137 | csharp_style_expression_bodied_lambdas = true:silent 138 | csharp_style_expression_bodied_local_functions = false:silent 139 | ############################### 140 | # VB Coding Conventions # 141 | ############################### 142 | [*.vb] 143 | # Modifier preferences 144 | visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion 145 | -------------------------------------------------------------------------------- /.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 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /DomainModeling.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainModeling.Web", "src\DomainModeling.Web\DomainModeling.Web.csproj", "{994C3835-22AA-4E00-9737-2A3F321D186D}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B2CFD51F-F689-4CD2-A932-BEDDD5B4830C}" 9 | ProjectSection(SolutionItems) = preProject 10 | .editorconfig = .editorconfig 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {994C3835-22AA-4E00-9737-2A3F321D186D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {994C3835-22AA-4E00-9737-2A3F321D186D}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {994C3835-22AA-4E00-9737-2A3F321D186D}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {994C3835-22AA-4E00-9737-2A3F321D186D}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {440799F9-E578-4409-A080-B5153E60F616} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Steve Smith 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 | # Domain Modeling 2 | 3 | Some examples showing domain modeling tips and traps 4 | 5 | ## Related Articles 6 | 7 | - [Domain Modeling - Anemic Models](https://ardalis.com/domain-modeling-anemic-models/) 8 | - [Domain Modeling - Encapsulation](https://ardalis.com/domain-modeling-encapsulation/) 9 | 10 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web; 2 | public abstract class BaseEntity 3 | { 4 | public int Id { get; set; } 5 | } 6 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/DomainModeling.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | .\DomainModeling.Web.xml 11 | CS1591 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/DomainModeling.Web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | DomainModeling.Web 5 | 6 | 7 | 8 | 9 | Completes a project and all of its todo items 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Gets a Project with its ToDoItems 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Sends interested parties notifications 26 | 27 | 28 | 29 | 30 | Represents a single task in a project 31 | 32 | 33 | 34 | 35 | Updates a ToDoItem 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | Completes a project and all of its todo items 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Gets a Project with its ToDoItems 52 | 53 | A Project Id 54 | 55 | 56 | 57 | 58 | 59 | Represents a single task in a project 60 | 61 | 62 | 63 | 64 | Updates a ToDoItem 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | Completes a project and all of its todo items 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | Gets a Project with its ToDoItems 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | Sends interested parties notifications 89 | 90 | 91 | 92 | 93 | Represents a single task in a project 94 | 95 | 96 | 97 | 98 | Handlers within domain entity classes can access private state of entities 99 | 100 | 101 | 102 | 103 | Updates a ToDoItem 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/Complete.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.Anemic; 6 | 7 | public class Complete : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | { 11 | /// 12 | /// Completes a project and all of its todo items 13 | /// 14 | /// 15 | /// 16 | /// 17 | [HttpPatch("[namespace]/projects/{projectId}")] 18 | [SwaggerOperation(Description = "Complete a Project", Summary = "Complete a Project", Tags = new[] { "Anemic" })] 19 | public override async Task> HandleAsync(int projectId, 20 | CancellationToken cancellationToken = default) 21 | { 22 | var project = (await Data.Projects) 23 | .FirstOrDefault(p => p.Id == projectId); 24 | if (project == null) return NotFound(); 25 | project.ToDoItems.ForEach(item => item.IsDone = true); 26 | 27 | return project; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/Data.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Anemic; 2 | 3 | public class Data 4 | { 5 | internal static List _projects = new(); 6 | 7 | public static Task> Projects => 8 | Task.FromResult>(_projects); 9 | 10 | internal static void Seed(ILogger logger) 11 | { 12 | int currentProjectId = 1; 13 | int currentTaskId = 1; 14 | var project = new Project() { Id = currentProjectId++, Name = "First Project!" }; 15 | project.ToDoItems.Add(new ToDoItem() { Id = currentTaskId++, Name = "Write Sample Code" }); 16 | project.ToDoItems.Add(new ToDoItem() { Id = currentTaskId++, Name = "Write Blog Post" }); 17 | project.ToDoItems.Add(new ToDoItem() { Id = currentTaskId++, Name = "Send Newsletter" }); 18 | 19 | _projects.Add(project); 20 | 21 | logger.LogInformation($"Data seeded in Anemic namespace"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/GetById.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.Anemic; 6 | 7 | public class GetById : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | // https://ardalis.com/your-api-and-view-models-should-not-reference-domain-models/ 11 | { 12 | /// 13 | /// Gets a Project with its ToDoItems 14 | /// 15 | /// A Project Id 16 | /// 17 | /// 18 | [HttpGet("[namespace]/projects/{id}")] 19 | [SwaggerOperation(Tags = new[] { "Anemic" })] 20 | public override async Task> HandleAsync(int id, 21 | CancellationToken cancellationToken = default) 22 | { 23 | var project = (await Data.Projects).FirstOrDefault(p => p.Id == id); 24 | if (project == null) return NotFound(); 25 | return Ok(project); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/Project.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Anemic; 2 | public class Project : BaseEntity 3 | { 4 | public string Name { get; set; } = ""; 5 | public List ToDoItems { get; set; } = new(); 6 | } 7 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/ToDoItem.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Anemic; 2 | /// 3 | /// Represents a single task in a project 4 | /// 5 | public class ToDoItem : BaseEntity 6 | { 7 | public string Name { get; set; } = ""; 8 | public string Description { get; set; } = ""; 9 | public bool IsDone { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/UpdateToDoItem.UpdateToDoItemRequest.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Anemic; 2 | 3 | public class UpdateToDoItemRequest 4 | { 5 | public int ProjectId { get; set; } 6 | public int ToDoItemId { get; set; } 7 | public string UpdatedName { get; set; } = ""; 8 | public bool UpdatedIsDone { get; set; } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Anemic/UpdateToDoItem.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.Anemic; 6 | 7 | public class UpdateToDoItem : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | { 11 | /// 12 | /// Updates a ToDoItem 13 | /// 14 | /// 15 | /// 16 | /// 17 | [HttpPut("[namespace]/projects")] 18 | public override async Task> HandleAsync(UpdateToDoItemRequest request, CancellationToken cancellationToken = default) 19 | { 20 | var project = (await Data.Projects) 21 | .FirstOrDefault(p => p.Id == request.ProjectId); 22 | if (project == null) return NotFound(); 23 | var item = project.ToDoItems 24 | .FirstOrDefault(i => i.Id == request.ToDoItemId); 25 | if (item == null) return NotFound(); 26 | item.IsDone = request.UpdatedIsDone; 27 | item.Name = request.UpdatedName; 28 | 29 | return project; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/Complete.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.AnemicV2; 6 | 7 | public class Complete : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | { 11 | /// 12 | /// Completes a project and all of its todo items 13 | /// 14 | /// 15 | /// 16 | /// 17 | [HttpPatch("[namespace]/projects/{projectId}")] 18 | [SwaggerOperation(Description = "Complete a Project", Summary = "Complete a Project", Tags = new[] { "Anemic" })] 19 | public override async Task> HandleAsync(int projectId, 20 | CancellationToken cancellationToken = default) 21 | { 22 | var project = (await Data.Projects) 23 | .FirstOrDefault(p => p.Id == projectId); 24 | if (project == null) return NotFound(); 25 | project.ToDoItems.ForEach(item => item.IsDone = true); // Notifications should be sent here but aren't 26 | 27 | return project; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/Data.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.AnemicV2; 2 | 3 | public class Data 4 | { 5 | internal static List _projects = new(); 6 | 7 | public static Task> Projects => 8 | Task.FromResult>(_projects); 9 | 10 | internal static void Seed(ILogger logger) 11 | { 12 | int currentProjectId = 1; 13 | int currentTaskId = 1; 14 | var project = new Project() { Id = currentProjectId++, Name = "First Project!" }; 15 | project.ToDoItems.Add(new ToDoItem() { Id = currentTaskId++, Name = "Write Sample Code" }); 16 | project.ToDoItems.Add(new ToDoItem() { Id = currentTaskId++, Name = "Write Blog Post" }); 17 | project.ToDoItems.Add(new ToDoItem() { Id = currentTaskId++, Name = "Send Newsletter" }); 18 | 19 | _projects.Add(project); 20 | 21 | logger.LogInformation($"Data seeded in AnemicV2 namespace"); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/GetById.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.AnemicV2; 6 | 7 | public class GetById : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | { 11 | /// 12 | /// Gets a Project with its ToDoItems 13 | /// 14 | /// 15 | /// 16 | /// 17 | [HttpGet("[namespace]/projects/{id}")] 18 | [SwaggerOperation(Tags = new[] { "Anemic" })] 19 | public override async Task> HandleAsync(int id, CancellationToken cancellationToken = default) 20 | { 21 | var project = (await Data.Projects).FirstOrDefault(p => p.Id == id); 22 | if (project == null) return NotFound(); 23 | return Ok(project); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/NotificationService.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace DomainModeling.Web.Endpoints.AnemicV2; 3 | 4 | /// 5 | /// Sends interested parties notifications 6 | /// 7 | public static class NotificationService 8 | { 9 | public static void NotifyToDoItemCompleted(ToDoItem item) 10 | { 11 | Console.WriteLine($"Item {item.Name} is complete."); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/Project.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.AnemicV2; 2 | public class Project : BaseEntity 3 | { 4 | public string Name { get; set; } = ""; 5 | public List ToDoItems { get; set; } = new(); 6 | } 7 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/ToDoItem.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.AnemicV2; 2 | 3 | /// 4 | /// Represents a single task in a project 5 | /// 6 | public class ToDoItem : BaseEntity 7 | { 8 | public string Name { get; set; } = ""; 9 | public string Description { get; set; } = ""; 10 | public bool IsDone { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/UpdateToDoItem.UpdateToDoItemRequest.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.AnemicV2; 2 | 3 | public class UpdateToDoItemRequest 4 | { 5 | public int ProjectId { get; set; } 6 | public int ToDoItemId { get; set; } 7 | public string UpdatedName { get; set; } = ""; 8 | public bool UpdatedIsDone { get; set; } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/AnemicV2/UpdateToDoItem.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace DomainModeling.Web.Endpoints.AnemicV2; 5 | 6 | public class UpdateToDoItem : EndpointBaseAsync 7 | .WithRequest 8 | .WithActionResult 9 | { 10 | /// 11 | /// Updates a ToDoItem 12 | /// 13 | /// 14 | /// 15 | /// 16 | [HttpPut("[namespace]/projects")] 17 | public override async Task> HandleAsync(UpdateToDoItemRequest request, 18 | CancellationToken cancellationToken = default) 19 | { 20 | var project = (await Data.Projects) 21 | .FirstOrDefault(p => p.Id == request.ProjectId); 22 | if (project == null) return NotFound(); 23 | var item = project.ToDoItems 24 | .FirstOrDefault(i => i.Id == request.ToDoItemId); 25 | if (item == null) return NotFound(); 26 | if (request.UpdatedIsDone) 27 | { 28 | NotificationService.NotifyToDoItemCompleted(item); 29 | } 30 | item.IsDone = request.UpdatedIsDone; 31 | item.Name = request.UpdatedName; 32 | 33 | return project; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/Complete.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.Encapsulated; 6 | 7 | public class Complete : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | { 11 | private readonly DataService _dataService; 12 | 13 | public Complete(DataService dataService) 14 | { 15 | _dataService = dataService; 16 | } 17 | 18 | /// 19 | /// Completes a project and all of its todo items 20 | /// 21 | /// 22 | /// 23 | /// 24 | [HttpPatch("[namespace]/projects/{projectId}")] 25 | [SwaggerOperation(Description = "Complete a Project", Summary = "Complete a Project", Tags = new[] { "Anemic" })] 26 | public override async Task> HandleAsync(int projectId, 27 | CancellationToken cancellationToken = default) 28 | { 29 | var project = (await DataService.Projects) 30 | .FirstOrDefault(p => p.Id == projectId); 31 | if (project == null) return NotFound(); 32 | project.ToDoItems.ForEach(item => item.MarkComplete()); // Notifications should be sent here but aren't 33 | 34 | return project; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/DataService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using MediatR; 3 | 4 | namespace DomainModeling.Web.Endpoints.Encapsulated; 5 | 6 | public class DataService 7 | { 8 | internal static ObservableCollection _projects = new(); 9 | 10 | public static Task> Projects => 11 | Task.FromResult>(_projects.ToList()); 12 | 13 | public IMediator Mediator { get; } 14 | 15 | public DataService(IMediator mediator) 16 | { 17 | Mediator = mediator; 18 | } 19 | 20 | public async Task SaveChanges() 21 | { 22 | foreach (var project in _projects) 23 | { 24 | foreach (var item in project.ToDoItems) 25 | { 26 | foreach (var domainEvent in item.Events) 27 | { 28 | await Mediator.Publish(domainEvent); 29 | } 30 | item.ClearDomainEvents(); 31 | } 32 | } 33 | } 34 | 35 | internal static void Seed(ILogger logger) 36 | { 37 | int currentProjectId = 1; 38 | int currentTaskId = 1; 39 | var project = new Project() { Id = currentProjectId++, Name = "First Project!" }; 40 | project.ToDoItems.Add(new ToDoItem("Write Sample Code") { Id = currentTaskId++ }); 41 | project.ToDoItems.Add(new ToDoItem("Write Blog Post") { Id = currentTaskId++ }); 42 | project.ToDoItems.Add(new ToDoItem("Send Newsletter") { Id = currentTaskId++ }); 43 | 44 | _projects.Add(project); 45 | 46 | logger.LogInformation($"Data seeded in Encapsulated namespace"); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/DomainEventBase.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace DomainModeling.Web.Endpoints.Encapsulated; 4 | 5 | public abstract record DomainEventBase : INotification 6 | { } 7 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/EntityBase.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Encapsulated; 2 | 3 | public abstract class EntityBase 4 | { 5 | public int Id { get; set; } 6 | 7 | private List _events = new(); 8 | internal IEnumerable Events => _events.AsReadOnly(); 9 | 10 | protected void RegisterDomainEvent(DomainEventBase domainEvent) => _events.Add(domainEvent); 11 | internal void ClearDomainEvents() => _events.Clear(); 12 | } 13 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/GetById.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Swashbuckle.AspNetCore.Annotations; 4 | 5 | namespace DomainModeling.Web.Endpoints.Encapsulated; 6 | 7 | public class GetById : EndpointBaseAsync 8 | .WithRequest 9 | .WithActionResult 10 | { 11 | 12 | private readonly DataService _dataService; 13 | 14 | public GetById(DataService dataService) 15 | { 16 | _dataService = dataService; 17 | } 18 | 19 | 20 | /// 21 | /// Gets a Project with its ToDoItems 22 | /// 23 | /// 24 | /// 25 | /// 26 | [HttpGet("[namespace]/projects/{id}")] 27 | [SwaggerOperation(Tags = new[] { "Anemic" })] 28 | public override async Task> HandleAsync(int id, CancellationToken cancellationToken = default) 29 | { 30 | var project = (await DataService.Projects).FirstOrDefault(p => p.Id == id); 31 | if (project == null) return NotFound(); 32 | return Ok(project); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/NotificationService.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace DomainModeling.Web.Endpoints.Encapsulated; 3 | 4 | /// 5 | /// Sends interested parties notifications 6 | /// 7 | public static class NotificationService 8 | { 9 | public static void NotifyToDoItemCompleted(ToDoItem item) 10 | { 11 | Console.WriteLine($"Item {item.Name} is complete."); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/Project.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Encapsulated; 2 | public class Project : EntityBase 3 | { 4 | public string Name { get; set; } = ""; 5 | public List ToDoItems { get; set; } = new(); 6 | } 7 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/ToDoItem.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.GuardClauses; 2 | using MediatR; 3 | 4 | namespace DomainModeling.Web.Endpoints.Encapsulated; 5 | 6 | /// 7 | /// Represents a single task in a project 8 | /// 9 | public class ToDoItem : EntityBase 10 | { 11 | public ToDoItem(string name) 12 | { 13 | Name = Guard.Against.NullOrEmpty(name, nameof(name)); 14 | } 15 | 16 | public string Name { get; set; } = ""; 17 | public string Description { get; private set; } = ""; 18 | public bool IsDone { get; private set; } 19 | 20 | public void MarkComplete() 21 | { 22 | if (IsDone) return; 23 | 24 | IsDone = true; 25 | RegisterDomainEvent(new ToDoItemCompletedEvent(this)); 26 | } 27 | 28 | /// 29 | /// Handlers within domain entity classes can access private state of entities 30 | /// 31 | public class CompletedItemHandler : INotificationHandler 32 | { 33 | public CompletedItemHandler() // TODO: Inject INotificationService here 34 | { 35 | } 36 | public Task Handle(ToDoItemCompletedEvent domainEvent, CancellationToken cancellationToken) 37 | { 38 | NotificationService.NotifyToDoItemCompleted(domainEvent.ToDoItem); 39 | 40 | return Task.CompletedTask; 41 | } 42 | } 43 | } 44 | 45 | // ToDoItem Events 46 | public record ToDoItemCompletedEvent(ToDoItem ToDoItem) : DomainEventBase; 47 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/UpdateToDoItem.UpdateToDoItemRequest.cs: -------------------------------------------------------------------------------- 1 | namespace DomainModeling.Web.Endpoints.Encapsulated; 2 | 3 | public class UpdateToDoItemRequest 4 | { 5 | public int ProjectId { get; set; } 6 | public int ToDoItemId { get; set; } 7 | public string UpdatedName { get; set; } = ""; 8 | public bool UpdatedIsDone { get; set; } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Endpoints/Encapsulated/UpdateToDoItem.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.ApiEndpoints; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace DomainModeling.Web.Endpoints.Encapsulated; 5 | 6 | public class UpdateToDoItem : EndpointBaseAsync 7 | .WithRequest 8 | .WithActionResult 9 | { 10 | 11 | private readonly DataService _dataService; 12 | 13 | public UpdateToDoItem(DataService dataService) 14 | { 15 | _dataService = dataService; 16 | } 17 | 18 | 19 | /// 20 | /// Updates a ToDoItem 21 | /// 22 | /// 23 | /// 24 | /// 25 | [HttpPut("[namespace]/projects")] 26 | public override async Task> HandleAsync(UpdateToDoItemRequest request, 27 | CancellationToken cancellationToken = default) 28 | { 29 | var project = (await DataService.Projects) 30 | .FirstOrDefault(p => p.Id == request.ProjectId); 31 | if (project == null) return NotFound(); 32 | var item = project.ToDoItems 33 | .FirstOrDefault(i => i.Id == request.ToDoItemId); 34 | if (item == null) return NotFound(); 35 | if (request.UpdatedIsDone) 36 | { 37 | item.MarkComplete(); 38 | } 39 | item.Name = request.UpdatedName; 40 | 41 | await _dataService.SaveChanges(); 42 | return project; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using DomainModeling.Web; 3 | using DomainModeling.Web.Endpoints.Encapsulated; 4 | using MediatR; 5 | using Microsoft.Extensions.PlatformAbstractions; 6 | using Microsoft.OpenApi.Models; 7 | using Serilog; 8 | 9 | var builder = WebApplication.CreateBuilder(args); 10 | 11 | builder.Host.UseSerilog((ctx, lc) => lc 12 | .WriteTo.Console()); 13 | 14 | // Add services to the container. 15 | 16 | builder.Services.AddControllers(options => 17 | { 18 | options.UseNamespaceRouteToken(); 19 | }); 20 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 21 | builder.Services.AddEndpointsApiExplorer(); 22 | builder.Services.AddMediatR(typeof(DomainModeling.Web.BaseEntity).Assembly); 23 | builder.Services.AddScoped(); 24 | builder.Services.AddSwaggerGen(c => 25 | { 26 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "Domain Modeling", Version = "v1" }); 27 | c.IncludeXmlComments(Program.XmlCommentsFilePath); 28 | c.CustomSchemaIds(x => x.FullName); 29 | c.UseApiEndpoints(); 30 | }); 31 | var app = builder.Build(); 32 | 33 | // Configure the HTTP request pipeline. 34 | if (app.Environment.IsDevelopment()) 35 | { 36 | app.UseSwagger(); 37 | app.UseSwaggerUI(); 38 | } 39 | 40 | app.UseHttpsRedirection(); 41 | 42 | app.UseAuthorization(); 43 | 44 | app.MapControllers(); 45 | 46 | // Configure Sample Data 47 | 48 | DomainModeling.Web.Endpoints.Anemic.Data.Seed(app.Logger); 49 | DomainModeling.Web.Endpoints.AnemicV2.Data.Seed(app.Logger); 50 | DataService.Seed(app.Logger); 51 | 52 | app.Run(); 53 | 54 | public partial class Program 55 | { 56 | static string XmlCommentsFilePath 57 | { 58 | get 59 | { 60 | var basePath = PlatformServices.Default.Application.ApplicationBasePath; 61 | var fileName = typeof(Program).GetTypeInfo().Assembly.GetName().Name + ".xml"; 62 | return Path.Combine(basePath, fileName); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:49304", 8 | "sslPort": 44374 9 | } 10 | }, 11 | "profiles": { 12 | "DomainModeling.Web": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:7224;http://localhost:5224", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/DomainModeling.Web/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | --------------------------------------------------------------------------------