├── .gitignore ├── .mailmap ├── AzureFunctionsV2DependencyInjectionSample.sln ├── LICENSE ├── README.md ├── Settings.StyleCop ├── src └── FunctionsV2DiSample.FunctionApp │ ├── .gitignore │ ├── AutofacGitHubRepositoriesHttpTrigger.cs │ ├── Configs │ └── GitHub.cs │ ├── Containers │ ├── ContainerBuilder.cs │ └── IContainerBuilder.cs │ ├── CoreGitHubRepositoriesHttpTrigger.cs │ ├── Extensions │ └── ConfigurationBinderExtensions.cs │ ├── Functions │ ├── AutofacFunctionFactory.cs │ ├── AutofacGitHubRepositoriesFunction.cs │ ├── CoreFunctionFactory.cs │ ├── CoreGitHubRepositoriesFunction.cs │ ├── FunctionOptions │ │ ├── FunctionOptionsBase.cs │ │ └── GitHubRepositoriesHttpTriggerOptions.cs │ ├── IFunction.cs │ ├── IFunctionFactory.cs │ └── IGitHubRepositoriesFunction.cs │ ├── FunctionsV2DiSample.FunctionApp.csproj │ ├── Modules │ ├── AutofacAppModule.cs │ ├── CoreAppModule.cs │ ├── IModule.cs │ └── Module.cs │ ├── config.json │ └── host.json └── test └── FunctionsV2DiSample.FunctionApp.Tests ├── CoreGitHubRepositoriesHttpTriggerTests.cs ├── Fixtures └── FakeQueryCollection.cs └── FunctionsV2DiSample.FunctionApp.Tests.csproj /.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 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # 2 | # This list is used by git-shortlog to fix a few botched name translations 3 | # in the git archive, either because the author's full name was messed up 4 | # and/or not always written the same way, making contributions from the 5 | # same person appearing not to be so. 6 | # 7 | # Reference: https://github.com/git/git/blob/master/.mailmap 8 | # 9 | 10 | Justin Yoo 11 | Justin Yoo 12 | Justin Yoo 13 | -------------------------------------------------------------------------------- /AzureFunctionsV2DependencyInjectionSample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{93282150-FCD3-4B13-99C6-5A71A1D2F967}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionsV2DiSample.FunctionApp", "src\FunctionsV2DiSample.FunctionApp\FunctionsV2DiSample.FunctionApp.csproj", "{5A939504-A3F7-4208-8599-F96FAAC817DF}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EFC49283-E92E-47C5-8998-721CFBF3BB13}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionsV2DiSample.FunctionApp.Tests", "test\FunctionsV2DiSample.FunctionApp.Tests\FunctionsV2DiSample.FunctionApp.Tests.csproj", "{F50077C3-4650-4330-B631-1DC9E09E19F1}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ADFD6F77-DC02-4ADD-A190-D046D9E12CD4}" 15 | ProjectSection(SolutionItems) = preProject 16 | .gitignore = .gitignore 17 | .mailmap = .mailmap 18 | LICENSE = LICENSE 19 | README.md = README.md 20 | Settings.StyleCop = Settings.StyleCop 21 | EndProjectSection 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Any CPU = Debug|Any CPU 26 | Release|Any CPU = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {5A939504-A3F7-4208-8599-F96FAAC817DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {5A939504-A3F7-4208-8599-F96FAAC817DF}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {5A939504-A3F7-4208-8599-F96FAAC817DF}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {5A939504-A3F7-4208-8599-F96FAAC817DF}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {F50077C3-4650-4330-B631-1DC9E09E19F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {F50077C3-4650-4330-B631-1DC9E09E19F1}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {F50077C3-4650-4330-B631-1DC9E09E19F1}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {F50077C3-4650-4330-B631-1DC9E09E19F1}.Release|Any CPU.Build.0 = Release|Any CPU 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | GlobalSection(NestedProjects) = preSolution 42 | {5A939504-A3F7-4208-8599-F96FAAC817DF} = {93282150-FCD3-4B13-99C6-5A71A1D2F967} 43 | {F50077C3-4650-4330-B631-1DC9E09E19F1} = {EFC49283-E92E-47C5-8998-721CFBF3BB13} 44 | EndGlobalSection 45 | GlobalSection(ExtensibilityGlobals) = postSolution 46 | SolutionGuid = {1D809443-901B-4D07-8205-2C4B97948128} 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Dev Kimchi (https://devkimchi.com) 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 | # Azure Functions V2 Dependency Injection Sample # 2 | 3 | This provides sample codes for Azure Functions V2, with regards to dependency injections. 4 | 5 | 6 | ## More Readings ## 7 | 8 | * English: Dependency Injections on Azure Functions V2 – [DevKimchi](https://devkimchi.com/#coming-soon), [Mexia](https://blog.mexia.com.au/#coming-soon) 9 | * 한국어: 애저 펑션 V2 에서 의존성 주입 및 관리 – [Aliencube](http://blog.aliencube.com/#coming-soon) 10 | 11 | ## Implementations ## 12 | 13 | * https://github.com/aliencube/AzureFunctions.Extensions 14 | * https://www.nuget.org/packages/Aliencube.AzureFunctions.Extensions.DependencyInjection/ 15 | 16 | 17 | ## Contribution ## 18 | 19 | Your contributions are always welcome! All your work should be done in your forked repository. Once you finish your work with corresponding tests, please send us a pull request onto our `master` branch for review. 20 | 21 | 22 | ## License ## 23 | 24 | This is released under [MIT License](http://opensource.org/licenses/MIT) 25 | 26 | > The MIT License (MIT) 27 | > 28 | > Copyright (c) 2018 [devkimchi.com](https://devkimchi.com) 29 | > 30 | > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 31 | > 32 | > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 33 | > 34 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | -------------------------------------------------------------------------------- /Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | en-US 6 | 7 | 8 | 9 | 10 | 11 | 12 | False 13 | 14 | 15 | 16 | 17 | False 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | False 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | False 38 | 39 | 40 | 41 | 42 | True 43 | 44 | 45 | 46 | 47 | 48 | 49 | False 50 | 51 | 52 | 53 | 54 | 55 | db 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # Azure Functions localsettings file 5 | local.settings.json 6 | 7 | # User-specific files 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 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # DNX 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | #*.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.jfm 196 | *.pfx 197 | *.publishsettings 198 | node_modules/ 199 | orleans.codegen.cs 200 | 201 | # Since there are multiple workflows, uncomment next line to ignore bower_components 202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 203 | #bower_components/ 204 | 205 | # RIA/Silverlight projects 206 | Generated_Code/ 207 | 208 | # Backup & report files from converting an old project file 209 | # to a newer Visual Studio version. Backup files are not needed, 210 | # because we have git ;-) 211 | _UpgradeReport_Files/ 212 | Backup*/ 213 | UpgradeLog*.XML 214 | UpgradeLog*.htm 215 | 216 | # SQL Server files 217 | *.mdf 218 | *.ldf 219 | 220 | # Business Intelligence projects 221 | *.rdl.data 222 | *.bim.layout 223 | *.bim_*.settings 224 | 225 | # Microsoft Fakes 226 | FakesAssemblies/ 227 | 228 | # GhostDoc plugin setting file 229 | *.GhostDoc.xml 230 | 231 | # Node.js Tools for Visual Studio 232 | .ntvs_analysis.dat 233 | 234 | # Visual Studio 6 build log 235 | *.plg 236 | 237 | # Visual Studio 6 workspace options file 238 | *.opt 239 | 240 | # Visual Studio LightSwitch build output 241 | **/*.HTMLClient/GeneratedArtifacts 242 | **/*.DesktopClient/GeneratedArtifacts 243 | **/*.DesktopClient/ModelManifest.xml 244 | **/*.Server/GeneratedArtifacts 245 | **/*.Server/ModelManifest.xml 246 | _Pvt_Extensions 247 | 248 | # Paket dependency manager 249 | .paket/paket.exe 250 | paket-files/ 251 | 252 | # FAKE - F# Make 253 | .fake/ 254 | 255 | # JetBrains Rider 256 | .idea/ 257 | *.sln.iml 258 | 259 | # CodeRush 260 | .cr/ 261 | 262 | # Python Tools for Visual Studio (PTVS) 263 | __pycache__/ 264 | *.pyc -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/AutofacGitHubRepositoriesHttpTrigger.cs: -------------------------------------------------------------------------------- 1 | //using System.Threading.Tasks; 2 | 3 | //using FunctionsV2DiSample.FunctionApp.Functions; 4 | //using FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions; 5 | //using FunctionsV2DiSample.FunctionApp.Modules; 6 | 7 | //using Microsoft.AspNetCore.Http; 8 | //using Microsoft.AspNetCore.Mvc; 9 | //using Microsoft.Azure.WebJobs; 10 | //using Microsoft.Azure.WebJobs.Extensions.Http; 11 | //using Microsoft.Azure.WebJobs.Host; 12 | 13 | //namespace FunctionsV2DiSample.FunctionApp 14 | //{ 15 | // /// 16 | // /// This represents the HTTP trigger entity to list all repositories for a given user or organisation from GitHub. 17 | // /// 18 | // public static class AutofacGitHubRepositoriesHttpTrigger 19 | // { 20 | // public static IFunctionFactory Factory = new AutofacFunctionFactory(new AutofacAppModule()); 21 | 22 | // /// 23 | // /// Invokes the HTTP trigger. 24 | // /// 25 | // /// 26 | // /// 27 | // /// Returns response. 28 | // [FunctionName("AutofacGitHubRepositoriesHttpTrigger")] 29 | // public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "autofac/repositories")]HttpRequest req, TraceWriter log) 30 | // { 31 | // var options = GetOptions(req); 32 | 33 | // var result = await Factory.Create(log, "github").InvokeAsync(req, options).ConfigureAwait(false); 34 | 35 | // return new OkObjectResult(result); 36 | // } 37 | 38 | // private static GitHubRepositoriesHttpTriggerOptions GetOptions(HttpRequest req) 39 | // { 40 | // return new GitHubRepositoriesHttpTriggerOptions(req); 41 | // } 42 | // } 43 | //} -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Configs/GitHub.cs: -------------------------------------------------------------------------------- 1 | namespace FunctionsV2DiSample.FunctionApp.Configs 2 | { 3 | /// 4 | /// This represents the config entity for GitHub API. 5 | /// 6 | public class GitHub 7 | { 8 | /// 9 | /// Gets or sets the base URL. 10 | /// 11 | public virtual string BaseUrl { get; set; } 12 | 13 | /// 14 | /// Gets or sets the set of endpoints. 15 | /// 16 | public virtual Endpoints Endpoints { get; set; } 17 | } 18 | 19 | /// 20 | /// This represents the config entity for GitHub API endpoints. 21 | /// 22 | public class Endpoints 23 | { 24 | /// 25 | /// Gets or sets the repository endpoint. 26 | /// 27 | public virtual string Repositories { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Containers/ContainerBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using FunctionsV2DiSample.FunctionApp.Modules; 4 | 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace FunctionsV2DiSample.FunctionApp.Containers 8 | { 9 | /// 10 | /// This represents the builder entity for IoC container. 11 | /// 12 | public class ContainerBuilder : IContainerBuilder 13 | { 14 | private readonly IServiceCollection _services; 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | public ContainerBuilder() 20 | { 21 | this._services = new ServiceCollection(); 22 | } 23 | 24 | /// 25 | public IContainerBuilder RegisterModule(IModule module = null) 26 | { 27 | if (module == null) 28 | { 29 | module = new Module(); 30 | } 31 | 32 | module.Load(this._services); 33 | 34 | return this; 35 | } 36 | 37 | /// 38 | public IServiceProvider Build() 39 | { 40 | var provider = this._services.BuildServiceProvider(); 41 | 42 | return provider; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Containers/IContainerBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using FunctionsV2DiSample.FunctionApp.Modules; 4 | 5 | namespace FunctionsV2DiSample.FunctionApp.Containers 6 | { 7 | /// 8 | /// This provides interfaces to the class. 9 | /// 10 | public interface IContainerBuilder 11 | { 12 | /// 13 | /// Registers a dependency collection module. 14 | /// 15 | /// instance. 16 | /// Returns instance. 17 | IContainerBuilder RegisterModule(IModule module = null); 18 | 19 | /// 20 | /// Builds the dependency container. 21 | /// 22 | /// Returns instance. 23 | IServiceProvider Build(); 24 | } 25 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/CoreGitHubRepositoriesHttpTrigger.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using FunctionsV2DiSample.FunctionApp.Functions; 4 | using FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions; 5 | using FunctionsV2DiSample.FunctionApp.Modules; 6 | 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Azure.WebJobs; 10 | using Microsoft.Azure.WebJobs.Extensions.Http; 11 | using Microsoft.Azure.WebJobs.Host; 12 | 13 | namespace FunctionsV2DiSample.FunctionApp 14 | { 15 | /// 16 | /// This represents the HTTP trigger entity to list all repositories for a given user or organisation from GitHub. 17 | /// 18 | public static class CoreGitHubRepositoriesHttpTrigger 19 | { 20 | public static IFunctionFactory Factory = new CoreFunctionFactory(new CoreAppModule()); 21 | 22 | /// 23 | /// Invokes the HTTP trigger. 24 | /// 25 | /// 26 | /// 27 | /// Returns response. 28 | [FunctionName("CoreGitHubRepositoriesHttpTrigger")] 29 | public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "core/repositories")]HttpRequest req, TraceWriter log) 30 | { 31 | var options = GetOptions(req); 32 | 33 | var result = await Factory.Create(log).InvokeAsync(req, options).ConfigureAwait(false); 34 | 35 | return new OkObjectResult(result); 36 | } 37 | 38 | private static GitHubRepositoriesHttpTriggerOptions GetOptions(HttpRequest req) 39 | { 40 | return new GitHubRepositoriesHttpTriggerOptions(req); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Extensions/ConfigurationBinderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Microsoft.Extensions.Configuration; 4 | 5 | namespace FunctionsV2DiSample.FunctionApp.Extensions 6 | { 7 | /// 8 | /// This represents the extension entity for class. 9 | /// 10 | public static class ConfigurationBinderExtensions 11 | { 12 | /// 13 | /// Gets the instance from the configuration. 14 | /// 15 | /// Type of instance. 16 | /// instance. 17 | /// Configuration key. 18 | /// Returns the instance from the configuration. 19 | public static T Get(this IConfiguration configuration, string key = null) 20 | { 21 | var instance = Activator.CreateInstance(); 22 | 23 | if (string.IsNullOrWhiteSpace(key)) 24 | { 25 | configuration.Bind(instance); 26 | 27 | return instance; 28 | } 29 | 30 | configuration.Bind(key, instance); 31 | 32 | return instance; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/AutofacFunctionFactory.cs: -------------------------------------------------------------------------------- 1 | //using Autofac; 2 | 3 | //using Microsoft.Azure.WebJobs.Host; 4 | 5 | //namespace FunctionsV2DiSample.FunctionApp.Functions 6 | //{ 7 | // /// 8 | // /// This represents the factory entity for functions. 9 | // /// 10 | // public class AutofacFunctionFactory : IFunctionFactory 11 | // { 12 | // private readonly IContainer _container; 13 | 14 | // /// 15 | // /// Initializes a new instance of the class. 16 | // /// 17 | // /// instance. 18 | // public AutofacFunctionFactory(Module module = null) 19 | // { 20 | // var builder = new ContainerBuilder(); 21 | // builder.RegisterModule(module); 22 | 23 | // this._container = builder.Build(); 24 | // } 25 | 26 | // /// 27 | // public TFunction Create(TraceWriter log, string name = null) 28 | // where TFunction : IFunction 29 | // { 30 | // // Resolve the function instance directly from the container. 31 | // var function = this._container.ResolveNamed(name); 32 | // function.Log = log; 33 | 34 | // return function; 35 | // } 36 | // } 37 | //} -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/AutofacGitHubRepositoriesFunction.cs: -------------------------------------------------------------------------------- 1 | //using System.Net.Http; 2 | //using System.Net.Http.Headers; 3 | //using System.Threading.Tasks; 4 | 5 | //using FunctionsV2DiSample.FunctionApp.Configs; 6 | //using FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions; 7 | 8 | //using Microsoft.Azure.WebJobs.Host; 9 | 10 | //using Newtonsoft.Json; 11 | 12 | //namespace FunctionsV2DiSample.FunctionApp.Functions 13 | //{ 14 | // /// 15 | // /// This represents the function entity for GitHub repositories. 16 | // /// 17 | // public class AutofacGitHubRepositoriesFunction : IFunction 18 | // { 19 | // private static MediaTypeWithQualityHeaderValue acceptHeader = new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"); 20 | // private static ProductInfoHeaderValue userAgentHeader = new ProductInfoHeaderValue("Mozilla", "5.0"); 21 | 22 | // private readonly GitHub _github; 23 | // private readonly HttpClient _httpClient; 24 | 25 | // public AutofacGitHubRepositoriesFunction(GitHub github, HttpClient httpClient) 26 | // { 27 | // this._github = github; 28 | // this._httpClient = httpClient; 29 | // } 30 | 31 | // /// 32 | // public TraceWriter Log { get; set; } 33 | 34 | // /// 35 | // public async Task InvokeAsync(TInput input, FunctionOptionsBase options) 36 | // { 37 | // var option = options as GitHubRepositoriesHttpTriggerOptions; 38 | 39 | // string result; 40 | 41 | // this.AddRequestHeaders(); 42 | 43 | // var requestUrl = $"{this._github.BaseUrl}{string.Format(this._github.Endpoints.Repositories, option.Type, option.Name)}"; 44 | // using (var message = await this._httpClient.GetAsync(requestUrl).ConfigureAwait(false)) 45 | // { 46 | // result = await message.Content.ReadAsStringAsync().ConfigureAwait(false); 47 | // } 48 | 49 | // var res = JsonConvert.DeserializeObject(result); 50 | 51 | // this.RemoveRequestHeaders(); 52 | 53 | // return (TOutput)res; 54 | // } 55 | 56 | // private void AddRequestHeaders() 57 | // { 58 | // // https://gist.github.com/BellaCode/c0ba0a842bbe22c9215e 59 | // this._httpClient.DefaultRequestHeaders.Accept.Add(acceptHeader); 60 | // this._httpClient.DefaultRequestHeaders.UserAgent.Add(userAgentHeader); 61 | // } 62 | 63 | // private void RemoveRequestHeaders() 64 | // { 65 | // this._httpClient.DefaultRequestHeaders.Accept.Remove(acceptHeader); 66 | // this._httpClient.DefaultRequestHeaders.UserAgent.Remove(userAgentHeader); 67 | // } 68 | // } 69 | //} -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/CoreFunctionFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using FunctionsV2DiSample.FunctionApp.Containers; 4 | using FunctionsV2DiSample.FunctionApp.Modules; 5 | 6 | using Microsoft.Azure.WebJobs.Host; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | namespace FunctionsV2DiSample.FunctionApp.Functions 10 | { 11 | /// 12 | /// This represents the factory entity for functions. 13 | /// 14 | public class CoreFunctionFactory : IFunctionFactory 15 | { 16 | private readonly IServiceProvider _container; 17 | 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | /// instance. 22 | public CoreFunctionFactory(IModule module = null) 23 | { 24 | this._container = new ContainerBuilder() 25 | .RegisterModule(module) 26 | .Build(); 27 | } 28 | 29 | /// 30 | public TFunction Create(TraceWriter log, string name = null) 31 | where TFunction : IFunction 32 | { 33 | // Resolve the function instance directly from the container. 34 | var function = this._container.GetService(); 35 | function.Log = log; 36 | 37 | return function; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/CoreGitHubRepositoriesFunction.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Net.Http.Headers; 3 | using System.Threading.Tasks; 4 | 5 | using FunctionsV2DiSample.FunctionApp.Configs; 6 | using FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions; 7 | 8 | using Microsoft.Azure.WebJobs.Host; 9 | 10 | using Newtonsoft.Json; 11 | 12 | namespace FunctionsV2DiSample.FunctionApp.Functions 13 | { 14 | /// 15 | /// This represents the function entity for GitHub repositories. 16 | /// 17 | public class CoreGitHubRepositoriesFunction : IGitHubRepositoriesFunction 18 | { 19 | private static MediaTypeWithQualityHeaderValue acceptHeader = new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"); 20 | private static ProductInfoHeaderValue userAgentHeader = new ProductInfoHeaderValue("Mozilla", "5.0"); 21 | 22 | private readonly GitHub _github; 23 | private readonly HttpClient _httpClient; 24 | 25 | public CoreGitHubRepositoriesFunction(GitHub github, HttpClient httpClient) 26 | { 27 | this._github = github; 28 | this._httpClient = httpClient; 29 | } 30 | 31 | /// 32 | public TraceWriter Log { get; set; } 33 | 34 | /// 35 | public async Task InvokeAsync(TInput input, FunctionOptionsBase options) 36 | { 37 | var option = options as GitHubRepositoriesHttpTriggerOptions; 38 | 39 | string result; 40 | 41 | this.AddRequestHeaders(); 42 | 43 | var requestUrl = $"{this._github.BaseUrl}{string.Format(this._github.Endpoints.Repositories, option.Type, option.Name)}"; 44 | using (var message = await this._httpClient.GetAsync(requestUrl).ConfigureAwait(false)) 45 | { 46 | result = await message.Content.ReadAsStringAsync().ConfigureAwait(false); 47 | } 48 | 49 | var res = JsonConvert.DeserializeObject(result); 50 | 51 | this.RemoveRequestHeaders(); 52 | 53 | return (TOutput)res; 54 | } 55 | 56 | private void AddRequestHeaders() 57 | { 58 | // https://gist.github.com/BellaCode/c0ba0a842bbe22c9215e 59 | this._httpClient.DefaultRequestHeaders.Accept.Add(acceptHeader); 60 | this._httpClient.DefaultRequestHeaders.UserAgent.Add(userAgentHeader); 61 | } 62 | 63 | private void RemoveRequestHeaders() 64 | { 65 | this._httpClient.DefaultRequestHeaders.Accept.Remove(acceptHeader); 66 | this._httpClient.DefaultRequestHeaders.UserAgent.Remove(userAgentHeader); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/FunctionOptions/FunctionOptionsBase.cs: -------------------------------------------------------------------------------- 1 | namespace FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions 2 | { 3 | /// 4 | /// This represents a base function options entity. This must be inherited. 5 | /// 6 | public abstract class FunctionOptionsBase 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/FunctionOptions/GitHubRepositoriesHttpTriggerOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | 3 | namespace FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions 4 | { 5 | /// 6 | /// This represents the options entity for the class. 7 | /// 8 | public class GitHubRepositoriesHttpTriggerOptions : FunctionOptionsBase 9 | { 10 | private readonly HttpRequest _req; 11 | 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// 16 | public GitHubRepositoriesHttpTriggerOptions(HttpRequest req) 17 | { 18 | this._req = req; 19 | } 20 | 21 | /// 22 | /// Gets the repository type - users or organisations. 23 | /// 24 | public string Type => this.GetRepositoryType(); 25 | 26 | /// 27 | /// Gets the repository name. 28 | /// 29 | public string Name => this.GetRepositoryName(); 30 | 31 | private string GetRepositoryType() 32 | { 33 | var type = this._req.Query["type"]; 34 | 35 | return type; 36 | } 37 | 38 | private string GetRepositoryName() 39 | { 40 | var name = this._req.Query["name"]; 41 | 42 | return name; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/IFunction.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions; 4 | 5 | using Microsoft.Azure.WebJobs.Host; 6 | 7 | namespace FunctionsV2DiSample.FunctionApp.Functions 8 | { 9 | /// 10 | /// This provides interfaces to functions. 11 | /// 12 | public interface IFunction 13 | { 14 | /// 15 | /// Gets or sets the instance. 16 | /// 17 | TraceWriter Log { get; set; } 18 | 19 | /// 20 | /// Invokes the function. 21 | /// 22 | /// Type of input. 23 | /// Type of output. 24 | /// Input instance. 25 | /// instance. 26 | /// Returns output instance. 27 | Task InvokeAsync(TInput input, FunctionOptionsBase options); 28 | } 29 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/IFunctionFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Azure.WebJobs.Host; 2 | 3 | namespace FunctionsV2DiSample.FunctionApp.Functions 4 | { 5 | /// 6 | /// This provides interfaces to the instance. 7 | /// 8 | public interface IFunctionFactory 9 | { 10 | /// 11 | /// Creates a function instance from the IoC container. 12 | /// 13 | /// Type of function. 14 | /// instance. 15 | /// Instance name. 16 | /// Returns the function instance. 17 | TFunction Create(TraceWriter log, string name = null) where TFunction : IFunction; 18 | } 19 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Functions/IGitHubRepositoriesFunction.cs: -------------------------------------------------------------------------------- 1 | namespace FunctionsV2DiSample.FunctionApp.Functions 2 | { 3 | /// 4 | /// This provides interfaces to the class. 5 | /// 6 | public interface IGitHubRepositoriesFunction : IFunction 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/FunctionsV2DiSample.FunctionApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0 4 | v2 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | PreserveNewest 15 | 16 | 17 | PreserveNewest 18 | Never 19 | 20 | 21 | PreserveNewest 22 | Never 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Modules/AutofacAppModule.cs: -------------------------------------------------------------------------------- 1 | //using System.IO; 2 | //using System.Net.Http; 3 | 4 | //using Autofac; 5 | 6 | //using FunctionsV2DiSample.FunctionApp.Configs; 7 | //using FunctionsV2DiSample.FunctionApp.Extensions; 8 | //using FunctionsV2DiSample.FunctionApp.Functions; 9 | 10 | //using Microsoft.Extensions.Configuration; 11 | 12 | //namespace FunctionsV2DiSample.FunctionApp.Modules 13 | //{ 14 | // public class AutofacAppModule : Autofac.Module 15 | // { 16 | // protected override void Load(ContainerBuilder builder) 17 | // { 18 | // var config = new ConfigurationBuilder() 19 | // .SetBasePath(Directory.GetCurrentDirectory()) 20 | // .AddJsonFile("config.json") 21 | // .Build(); 22 | // var github = config.Get("github"); 23 | // builder.RegisterInstance(github).As().SingleInstance(); 24 | 25 | // var httpClient = new HttpClient(); 26 | // builder.RegisterInstance(httpClient).As().SingleInstance(); 27 | 28 | // builder.RegisterType().Named("github").InstancePerLifetimeScope(); 29 | // } 30 | // } 31 | //} 32 | -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Modules/CoreAppModule.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Net.Http; 3 | 4 | using FunctionsV2DiSample.FunctionApp.Configs; 5 | using FunctionsV2DiSample.FunctionApp.Extensions; 6 | using FunctionsV2DiSample.FunctionApp.Functions; 7 | 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace FunctionsV2DiSample.FunctionApp.Modules 12 | { 13 | /// 14 | /// This represents the module entity for dependencies. 15 | /// 16 | public class CoreAppModule : Module 17 | { 18 | /// 19 | public override void Load(IServiceCollection services) 20 | { 21 | var config = new ConfigurationBuilder() 22 | .SetBasePath(Directory.GetCurrentDirectory()) 23 | .AddJsonFile("config.json") 24 | .Build(); 25 | var github = config.Get("github"); 26 | 27 | services.AddSingleton(github); 28 | services.AddSingleton(); 29 | services.AddTransient(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Modules/IModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace FunctionsV2DiSample.FunctionApp.Modules 4 | { 5 | /// 6 | /// This provides interfaces to the class. 7 | /// 8 | public interface IModule 9 | { 10 | /// 11 | /// Loads dependencies to the collection. 12 | /// 13 | /// instance. 14 | void Load(IServiceCollection services); 15 | } 16 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/Modules/Module.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace FunctionsV2DiSample.FunctionApp.Modules 4 | { 5 | /// 6 | /// This represents the entity containing a list of dependencies. 7 | /// 8 | public class Module : IModule 9 | { 10 | /// 11 | public virtual void Load(IServiceCollection services) 12 | { 13 | return; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "github": { 3 | "baseUrl": "https://api.github.com/", 4 | "endpoints": { 5 | "repositories": "{0}/{1}/repos" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /src/FunctionsV2DiSample.FunctionApp/host.json: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /test/FunctionsV2DiSample.FunctionApp.Tests/CoreGitHubRepositoriesHttpTriggerTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using FluentAssertions; 4 | 5 | using FunctionsV2DiSample.FunctionApp.Functions; 6 | using FunctionsV2DiSample.FunctionApp.Functions.FunctionOptions; 7 | using FunctionsV2DiSample.FunctionApp.Tests.Fixtures; 8 | 9 | using Microsoft.AspNetCore.Http; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.Azure.WebJobs.Extensions; 12 | using Microsoft.Azure.WebJobs.Host; 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; 14 | 15 | using Moq; 16 | 17 | namespace FunctionsV2DiSample.FunctionApp.Tests 18 | { 19 | [TestClass] 20 | public class CoreGitHubRepositoriesHttpTriggerTests 21 | { 22 | [TestMethod] 23 | public async Task Given_TypeAndName_Run_Should_Return_Result() 24 | { 25 | var result = new { Hello = "World" }; 26 | 27 | var function = new Mock(); 28 | function.Setup(p => p.InvokeAsync(It.IsAny(), It.IsAny())).ReturnsAsync(result); 29 | 30 | var factory = new Mock(); 31 | factory.Setup(p => p.Create(It.IsAny(), It.IsAny())).Returns(function.Object); 32 | 33 | CoreGitHubRepositoriesHttpTrigger.Factory = factory.Object; 34 | 35 | var query = new FakeQueryCollection(); 36 | query["type"] = "lorem"; 37 | query["name"] = "ipsum"; 38 | 39 | var req = new Mock(); 40 | req.SetupGet(p => p.Query).Returns(query); 41 | 42 | var log = new TraceMonitor(); 43 | var response = await CoreGitHubRepositoriesHttpTrigger.Run(req.Object, log).ConfigureAwait(false); 44 | 45 | response.Should().BeOfType(); 46 | (response as OkObjectResult).Value.Should().Be(result); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /test/FunctionsV2DiSample.FunctionApp.Tests/Fixtures/FakeQueryCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.Extensions.Primitives; 6 | 7 | namespace FunctionsV2DiSample.FunctionApp.Tests.Fixtures 8 | { 9 | public class FakeQueryCollection : IQueryCollection 10 | { 11 | private readonly Dictionary _values; 12 | 13 | public FakeQueryCollection() 14 | { 15 | this._values = new Dictionary(); 16 | } 17 | 18 | public StringValues this[string key] 19 | { 20 | get { return this._values[key]; } 21 | set { this._values[key] = value; } 22 | } 23 | 24 | public int Count => throw new System.NotImplementedException(); 25 | 26 | public ICollection Keys => throw new System.NotImplementedException(); 27 | 28 | public bool ContainsKey(string key) 29 | { 30 | throw new System.NotImplementedException(); 31 | } 32 | 33 | public IEnumerator> GetEnumerator() 34 | { 35 | throw new System.NotImplementedException(); 36 | } 37 | 38 | public bool TryGetValue(string key, out StringValues value) 39 | { 40 | throw new System.NotImplementedException(); 41 | } 42 | 43 | IEnumerator IEnumerable.GetEnumerator() 44 | { 45 | throw new System.NotImplementedException(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /test/FunctionsV2DiSample.FunctionApp.Tests/FunctionsV2DiSample.FunctionApp.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | --------------------------------------------------------------------------------