diff --git a/.editorconfig b/.editorconfig index 8bbed11..9337e41 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,23 +6,185 @@ root = true [*] -end_of_line = CRLF - -[*.{config,cs,json,xml}] indent_style = space -indent_size = 4 trim_trailing_whitespace = true +insert_final_newline = true + +; .NET Code - almost, but not exactly, the same suggestions as corefx +; https://github.com/dotnet/corefx/blob/master/.editorconfig +[*.cs] +indent_size = 4 +charset = utf-8-bom + +; New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +; Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_switch_labels = true +csharp_indent_labels = one_less_than_current + +; Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +; Avoid this. unless absolutely necessary +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +; Types: use keywords instead of BCL types, using var is fine. +csharp_style_var_when_type_is_apparent = false:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +; Name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +; Static fields should be PascalCase +dotnet_naming_rule.static_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.static_fields_should_be_pascal_case.symbols = static_fields +dotnet_naming_rule.static_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected + +; Internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +; Code style defaults +csharp_using_directive_placement = outside_namespace:suggestion +dotnet_sort_system_directives_first = true +csharp_prefer_braces = true:refactoring +csharp_preserve_single_line_blocks = true:none +csharp_preserve_single_line_statements = false:none +csharp_prefer_static_local_function = true:suggestion +csharp_prefer_simple_using_statement = false:none +csharp_style_prefer_switch_expression = true:suggestion + +; Code quality +dotnet_style_readonly_field = true:suggestion +dotnet_code_quality_unused_parameters = non_public:suggestion + +; Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring +dotnet_style_prefer_conditional_expression_over_return = true:refactoring +csharp_prefer_simple_default_expression = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_methods = true:refactoring +csharp_style_expression_bodied_constructors = true:refactoring +csharp_style_expression_bodied_operators = true:refactoring +csharp_style_expression_bodied_properties = true:refactoring +csharp_style_expression_bodied_indexers = true:refactoring +csharp_style_expression_bodied_accessors = true:refactoring +csharp_style_expression_bodied_lambdas = true:refactoring +csharp_style_expression_bodied_local_functions = true:refactoring + +# Pattern matching +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +# Null checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Other features +csharp_style_prefer_index_operator = false:none +csharp_style_prefer_range_operator = false:none +csharp_style_pattern_local_over_anonymous_function = false:none + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false -[*.{proj,props,sln,targets}] +; .NET project files and MSBuild - match defaults for VS +[*.{csproj,nuspec,proj,projitems,props,shproj,targets,vbproj,vcxproj,vcxproj.filters,vsixmanifest,vsct}] +indent_size = 2 + +; .NET solution files - match defaults for VS +[*.sln] indent_style = tab -trim_trailing_whitespace = true -[*.{kproj,csproj,ps1,resx,rst}] -indent_style = space +; Config - match XML and default nuget.config template +[*.config] indent_size = 2 -trim_trailing_whitespace = true -[NuGet.Config] -indent_style = space +; Resources - match defaults for VS +[*.resx] +indent_size = 2 + +; Static analysis rulesets - match defaults for VS +[*.ruleset] +indent_size = 2 + +; HTML, XML - match defaults for VS +[*.{cshtml,html,xml}] +indent_size = 4 + +; JavaScript and JS mixes - match eslint settings; JSON also matches .NET Core templates +[*.{js,json,ts,vue}] +indent_size = 2 + +; Markdown - match markdownlint settings +[*.{md,markdown}] +indent_size = 2 + +; PowerShell - match defaults for New-ModuleManifest and PSScriptAnalyzer Invoke-Formatter +[*.{ps1,psd1,psm1}] +indent_size = 4 +charset = utf-8-bom + +; ReStructuredText - standard indentation format from examples +[*.rst] indent_size = 2 -trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index b4ac624..78f36f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,50 +1,41 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +# Project specific files +artifacts/ +BenchmarkDotNet.Artifacts/ + # User-specific files *.suo *.user -*.docstates -*.cache -*.userprefs -project.lock.json -.vs/ -.cr/ -[Ii]ndex.dat -[Ss]torage.dat +*.sln.docstates +*.ide +Index.dat +Storage.dat # Build results [Dd]ebug/ -[Dd]ebugPublic/ [Rr]elease/ -[Rr]eleases/ x64/ -x86/ -build/ -bld/ [Bb]in/ [Oo]bj/ -[Aa]rtifacts/ -# Roslyn cache directories -*.ide/ +# Visual Studio 2015 cache/options directory +.dotnet/ +.vs/ +.cr/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +!packages/*/build/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* - -#NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c +*.TestResults.xml +results/ *_i.c *_p.c -*_i.h *.ilk *.meta *.obj @@ -64,16 +55,12 @@ dlldata.c *.vssscc .builds *.pidb -*.svclog +*.log *.scc -# Chutzpah Test files -_Chutzpah* - # Visual C++ cache files ipch/ *.aps -*.ipch *.ncb *.opensdf *.sdf @@ -84,19 +71,12 @@ ipch/ *.vsp *.vspx -# TFS 2012 Local Workspace -$tf/ - # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding addin-in -.JustCode # TeamCity is a build add-in _TeamCity* @@ -104,17 +84,14 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# Coverage +coverage.* +codecov.sh +coverage/ + # NCrunch -_NCrunch_* +*.ncrunch* .*crunch*.local.xml -*.ncrunchsolution - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ # Installshield output folder [Ee]xpress/ @@ -134,29 +111,14 @@ publish/ # Publish Web Output *.[Pp]ublish.xml -*.azurePubxml -[Pp]ublish[Pp]rofiles/ -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted *.pubxml -*.publishproj - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Don't check in NuGet proper -.nuget/ -nuget.exe -# If using the old MSBuild-Integrated Package Restore, uncomment this: -#!**/packages/repositories.config -# Local filesystem/test NuGet -local-nuget/ + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +packages/ # Windows Azure Build Output -csx/ +csx *.build.csdef # Windows Store app package directory @@ -167,36 +129,47 @@ sql/ *.Cache ClientBin/ [Ss]tyle[Cc]op.* +!stylecop.json ~$* *~ *.dbmdl -*.dbproj.schemaview *.pfx *.publishsettings node_modules/ +bower_components/ +wwwroot/ +project.lock.json # RIA/Silverlight projects Generated_Code/ -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # SQL Server files -*.mdf -*.ldf +App_Data/*.mdf +App_Data/*.ldf + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings +# Recycle Bin used on file shares +$RECYCLE.BIN/ -# Microsoft Fakes -FakesAssemblies/ +# Mac crap +.DS_Store -# Mac OS -*DS_Store \ No newline at end of file +# JetBrains Rider +.idea diff --git a/Autofac.WebApi.Owin.sln b/Autofac.WebApi.Owin.sln index 0633aca..a82a493 100644 --- a/Autofac.WebApi.Owin.sln +++ b/Autofac.WebApi.Owin.sln @@ -1,11 +1,25 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autofac.Integration.WebApi.Owin", "src\Autofac.Integration.WebApi.Owin\Autofac.Integration.WebApi.Owin.csproj", "{1A3E68CF-E1D5-4E30-96C3-9B8687DF9283}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autofac.Integration.WebApi.Owin", "src\Autofac.Integration.WebApi.Owin\Autofac.Integration.WebApi.Owin.csproj", "{1A3E68CF-E1D5-4E30-96C3-9B8687DF9283}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autofac.Integration.WebApi.Owin.Test", "test\Autofac.Integration.WebApi.Owin.Test\Autofac.Integration.WebApi.Owin.Test.csproj", "{2EF2FBB2-77D0-4D85-936E-5A00881CF5F6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autofac.Integration.WebApi.Owin.Test", "test\Autofac.Integration.WebApi.Owin.Test\Autofac.Integration.WebApi.Owin.Test.csproj", "{2EF2FBB2-77D0-4D85-936E-5A00881CF5F6}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D372C752-2D55-4E5D-943B-CEDD5BD00747}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9AD9DBFC-4F7F-4EEB-98D5-AD23D64B7518}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{01223B84-9EDA-4971-AEFE-491579D4E1D7}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + appveyor.yml = appveyor.yml + global.json = global.json + LICENSE = LICENSE + NuGet.Config = NuGet.Config + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -25,4 +39,11 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1A3E68CF-E1D5-4E30-96C3-9B8687DF9283} = {D372C752-2D55-4E5D-943B-CEDD5BD00747} + {2EF2FBB2-77D0-4D85-936E-5A00881CF5F6} = {9AD9DBFC-4F7F-4EEB-98D5-AD23D64B7518} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {12B13373-B4BB-41C8-BD7E-73095EB2DEEB} + EndGlobalSection EndGlobal diff --git a/CodeAnalysisDictionary.xml b/CodeAnalysisDictionary.xml deleted file mode 100644 index 0f1b469..0000000 --- a/CodeAnalysisDictionary.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - Api - Autofac - autowired - autowiring - composable - configurator - Ioc - Mef - Moq - multitenancy - Mvc - Mvx - Mvvm - startable - Owin - - - - - diff --git a/Full.ruleset b/Full.ruleset deleted file mode 100644 index 417a489..0000000 --- a/Full.ruleset +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/NuGet.Config b/NuGet.Config index c62bcf4..e0e3e4e 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -6,7 +6,4 @@ - - - diff --git a/appveyor.yml b/appveyor.yml index 133e268..339b511 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,32 +1,38 @@ -environment: - package_semantic_version: 5.0.0 - assembly_semantic_version: 5.0.0 - -version: $(package_semantic_version).{build} - image: Visual Studio 2019 -assembly_info: +version: 6.0.0.{build} + +dotnet_csproj: + version_prefix: '6.0.0' patch: true - file: '**\AssemblyInfo.*' - assembly_version: '$(assembly_semantic_version).0' - assembly_file_version: '$(appveyor_build_version)' - assembly_informational_version: '$(package_semantic_version)-CI-{build}' + file: 'src\**\*.csproj' configuration: Release -before_build: -- nuget restore +environment: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + NUGET_XMLDOC_MODE: skip + +skip_tags: true + +nuget: + disable_publish_on_pr: true + +clone_depth: 1 + +test: off -build: - verbosity: minimal - publish_nuget: true - publish_nuget_symbols: true +build_script: + - ps: .\build.ps1 + +artifacts: + - path: artifacts\packages\**\*.nupkg + name: MyGet deploy: - provider: NuGet server: https://www.myget.org/F/autofac/api/v2/package api_key: secure: rCUEY75fXN0wxtMy6QL4jCrLdaYbxIBzIXWeN+wEu/XDpyqimzreOc5AH5jMd5ah - skip_symbols: true + skip_symbols: false symbol_server: https://www.myget.org/F/autofac/symbols/api/v2/package diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..1d154bd --- /dev/null +++ b/build.ps1 @@ -0,0 +1,46 @@ +######################## +# THE BUILD! +######################## + +Push-Location $PSScriptRoot +Import-Module $PSScriptRoot\Build\Autofac.Build.psd1 -Force + +$artifactsPath = "$PSScriptRoot\artifacts" +$packagesPath = "$artifactsPath\packages" +$sdkVersion = (Get-Content "$PSScriptRoot\global.json" | ConvertFrom-Json).sdk.version + +# Clean up artifacts folder +if (Test-Path $artifactsPath) { + Write-Message "Cleaning $artifactsPath folder" + Remove-Item $artifactsPath -Force -Recurse +} + +# Install dotnet CLI +Write-Message "Installing .NET Core SDK version $sdkVersion" +Install-DotNetCli -Version $sdkVersion + +# Write out dotnet information +& dotnet --info + +# Set version suffix +$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; +$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; +$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] + +Write-Message "Package version suffix is '$versionSuffix'" + +# Package restore +Write-Message "Restoring packages" +Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages + +# Build/package +Write-Message "Building projects and packages" +Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix + +# Test +Write-Message "Executing unit tests" +Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Invoke-Test + +# Finished +Write-Message "Build finished" +Pop-Location diff --git a/build/Analyzers.ruleset b/build/Analyzers.ruleset new file mode 100644 index 0000000..5a0a0b7 --- /dev/null +++ b/build/Analyzers.ruleset @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/Autofac.Build.psd1 b/build/Autofac.Build.psd1 new file mode 100644 index 0000000..5d93715 --- /dev/null +++ b/build/Autofac.Build.psd1 @@ -0,0 +1,15 @@ +@{ + RootModule = '.\Autofac.Build.psm1' + ModuleVersion = '0.2.0' + GUID = '55d3f738-f48f-4497-9b2c-ecd90ec1f978' + Author = 'Autofac Contributors' + CompanyName = 'Autofac' + Description = 'Build support for Autofac projects.' + FunctionsToExport = '*' + CmdletsToExport = '*' + VariablesToExport = '*' + AliasesToExport = '*' + ModuleList = @() + FileList = @() + PrivateData = '' +} \ No newline at end of file diff --git a/build/Autofac.Build.psm1 b/build/Autofac.Build.psm1 new file mode 100644 index 0000000..6cefea0 --- /dev/null +++ b/build/Autofac.Build.psm1 @@ -0,0 +1,250 @@ +# EXIT CODES +# 1: dotnet packaging failure +# 2: dotnet publishing failure +# 3: Unit test failure +# 4: dotnet / NuGet package restore failure + +<# + .SYNOPSIS + Writes a build progress message to the host. + + .PARAMETER Message + The message to write. +#> +function Write-Message +{ + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)] + [ValidateNotNullOrEmpty()] + [string] + $Message + ) + + Write-Host "[BUILD] $Message" -ForegroundColor Cyan +} + +<# + .SYNOPSIS + Gets the set of directories in which projects are available for compile/processing. + + .PARAMETER RootPath + Path where searching for project directories should begin. +#> +function Get-DotNetProjectDirectory +{ + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)] + [ValidateNotNullOrEmpty()] + [string] + $RootPath + ) + + Get-ChildItem -Path $RootPath -Recurse -Include "*.csproj" | Select-Object @{ Name="ParentFolder"; Expression={ $_.Directory.FullName.TrimEnd("\") } } | Select-Object -ExpandProperty ParentFolder +} + +<# + .SYNOPSIS + Runs the dotnet CLI install script from GitHub to install a project-local + copy of the CLI. +#> +function Install-DotNetCli +{ + [CmdletBinding()] + Param( + [string] + $Version = "Latest" + ) + + if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue)) + { + $installedVersion = dotnet --version + if ($installedVersion -eq $Version) + { + Write-Message ".NET Core SDK version $Version is already installed" + return; + } + } + + $callerPath = Split-Path $MyInvocation.PSCommandPath + $installDir = Join-Path -Path $callerPath -ChildPath ".dotnet\cli" + if (!(Test-Path $installDir)) + { + New-Item -ItemType Directory -Path "$installDir" | Out-Null + } + + # Download the dotnet CLI install script + if (!(Test-Path .\dotnet\install.ps1)) + { + Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile ".\.dotnet\dotnet-install.ps1" + } + + # Run the dotnet CLI install + & .\.dotnet\dotnet-install.ps1 -InstallDir "$installDir" -Version $Version + + # Add the dotnet folder path to the process. + $env:PATH = "$installDir;$env:PATH" +} + +<# +.SYNOPSIS + Builds a project using dotnet cli. +.DESCRIPTION + Builds a project in a specified directory using the dotnet cli. +.PARAMETER DirectoryName + The path to the directory containing the project to build. +#> +function Invoke-DotNetBuild +{ + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] + [ValidateNotNull()] + [System.IO.DirectoryInfo[]] + $ProjectDirectory + ) + Process + { + foreach($Project in $ProjectDirectory) + { + & dotnet build ("""" + $Project.FullName + """") --configuration Release + if ($LASTEXITCODE -ne 0) + { + exit 1 + } + } + } +} + +<# + .SYNOPSIS + Invokes the dotnet utility to package a project. + + .PARAMETER ProjectDirectory + Path to the directory containing the project to package. + + .PARAMETER PackagesPath + Path to the "artifacts\packages" folder where packages should go. + + .PARAMETER VersionSuffix + The version suffix to use for the NuGet package version. +#> +function Invoke-DotNetPack +{ + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] + [ValidateNotNull()] + [System.IO.DirectoryInfo[]] + $ProjectDirectory, + + [Parameter(Mandatory=$True, ValueFromPipeline=$False)] + [ValidateNotNull()] + [System.IO.DirectoryInfo] + $PackagesPath, + + [Parameter(Mandatory=$True, ValueFromPipeline=$False)] + [AllowEmptyString()] + [string] + $VersionSuffix + ) + Begin + { + New-Item -Path $PackagesPath -ItemType Directory -Force | Out-Null + } + Process + { + foreach($Project in $ProjectDirectory) + { + if ($VersionSuffix -eq "") + { + & dotnet build ("""" + $Project.FullName + """") --configuration Release + } + else + { + & dotnet build ("""" + $Project.FullName + """") --configuration Release --version-suffix $VersionSuffix + } + if ($LASTEXITCODE -ne 0) + { + exit 1 + } + + if ($VersionSuffix -eq "") + { + & dotnet pack ("""" + $Project.FullName + """") --configuration Release --output $PackagesPath + } + else + { + & dotnet pack ("""" + $Project.FullName + """") --configuration Release --version-suffix $VersionSuffix --output $PackagesPath + } + if ($LASTEXITCODE -ne 0) + { + exit 1 + } + } + } +} + +<# + .Synopsis + Invokes dotnet test command. + + .Parameter ProjectDirectory + Path to the directory containing the project to package. +#> +function Invoke-Test +{ + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] + [ValidateNotNull()] + [System.IO.DirectoryInfo[]] + $ProjectDirectory + ) + Process + { + foreach($Project in $ProjectDirectory) + { + Push-Location $Project + + & dotnet test --configuration Release --logger:trx + if ($LASTEXITCODE -ne 0) + { + Pop-Location + exit 3 + } + + Pop-Location + } + } +} + +<# + .SYNOPSIS + Restores dependencies using the dotnet utility. + + .PARAMETER ProjectDirectory + Path to the directory containing the project with dependencies to restore. +#> +function Restore-DependencyPackages +{ + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] + [ValidateNotNull()] + [System.IO.DirectoryInfo[]] + $ProjectDirectory + ) + Process + { + foreach($Project in $ProjectDirectory) + { + & dotnet restore ("""" + $Project.FullName + """") --no-cache + if($LASTEXITCODE -ne 0) + { + exit 4 + } + } + } +} diff --git a/build/icon.png b/build/icon.png new file mode 100644 index 0000000..4405a81 Binary files /dev/null and b/build/icon.png differ diff --git a/build/stylecop.json b/build/stylecop.json new file mode 100644 index 0000000..8f5c703 --- /dev/null +++ b/build/stylecop.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "companyName": "Autofac Project", + "copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the {licenseName} License. See {licenseFile} in the project root for license information.", + "variables": { + "licenseFile": "LICENSE", + "licenseName": "MIT" + }, + "xmlHeader": false + } + } +} diff --git a/global.json b/global.json new file mode 100644 index 0000000..14d6b1b --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "3.1.301", + "rollForward": "latestFeature" + } +} diff --git a/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.csproj b/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.csproj index b7468e1..32cf521 100644 --- a/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.csproj +++ b/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.csproj @@ -1,98 +1,58 @@ - - - - - Debug - AnyCPU - {1A3E68CF-E1D5-4E30-96C3-9B8687DF9283} - Library - Properties - Autofac.Integration.WebApi.Owin - Autofac.Integration.WebApi.Owin - v4.6.1 - 512 - ..\..\..\..\ - true - - /assemblyCompareMode:StrongNameIgnoringVersion - - - true - full - false - bin\Debug\ - TRACE;DEBUG;CODE_ANALYSIS - prompt - 4 - true - ..\..\Full.ruleset - bin\Debug\Autofac.Integration.WebApi.Owin.xml - - - pdbonly - true - bin\Release\ - TRACE;CODE_ANALYSIS - prompt - 4 - true - ..\..\Full.ruleset - bin\Release\Autofac.Integration.WebApi.Owin.xml - + + net472 true - - + + 0.0.1 ..\..\Autofac.snk + ..\..\build\Analyzers.ruleset + https://github.com/autofac/Autofac.WebApi.Owin + true + icon.png + https://autofac.org + MIT + Release notes are at https://github.com/autofac/Autofac.WebApi.Owin/releases + Autofac.WebApi2.Owin + Autofac.Integration.WebApi.Owin + Autofac + Autofac Contributors + Autofac + en-US + Autofac Web API Owin Integration + Copyright © 2014 Autofac Contributors + true + true + ../../build/Analyzers.ruleset + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + - - - - - - - - - - - - - + + - - + + - - CodeAnalysisDictionary.xml - Designer - - - - - 5.0.0 - - - 5.0.1 + + + + + + All - - 5.0.0 + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - 5.2.0 + + All - - 5.0.8 + + All + - - \ No newline at end of file diff --git a/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.nuspec b/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.nuspec deleted file mode 100644 index 4295e6f..0000000 --- a/src/Autofac.Integration.WebApi.Owin/Autofac.Integration.WebApi.Owin.nuspec +++ /dev/null @@ -1,22 +0,0 @@ - - - - Autofac.WebApi2.Owin - $version$ - Autofac Contributors - https://opensource.org/licenses/mit-license.php - false - OWIN support for the ASP.NET Web API 2.2 Integration for Autofac - Allows an Autofac lifetime scope to extend from the OWIN pipeline through to ASP.NET Web API. - en-US - Autofac ASP.NET Web API 2.2 OWIN Integration - https://autofac.org - https://cloud.githubusercontent.com/assets/1156571/13684110/16b8f152-e6bf-11e5-84ae-22c66c6d351a.png - Release notes are at https://github.com/autofac/Autofac.WebApi.Owin/releases - - - - - - - diff --git a/src/Autofac.Integration.WebApi.Owin/AutofacWebApiAppBuilderExtensions.cs b/src/Autofac.Integration.WebApi.Owin/AutofacWebApiAppBuilderExtensions.cs index 1132118..69e00dd 100644 --- a/src/Autofac.Integration.WebApi.Owin/AutofacWebApiAppBuilderExtensions.cs +++ b/src/Autofac.Integration.WebApi.Owin/AutofacWebApiAppBuilderExtensions.cs @@ -1,27 +1,5 @@ -// This software is part of the Autofac IoC container -// Copyright © 2014 Autofac Contributors -// https://autofac.org -// -// 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: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// 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. +// Copyright (c) Autofac Project. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. using System; using System.ComponentModel; @@ -43,21 +21,21 @@ public static class AutofacWebApiAppBuilderExtensions /// /// The application builder. /// The HTTP server configuration. - /// The application builder. + /// The application builder for continued configuration. /// /// Thrown if or is . /// - [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] + [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The handler created must exist for the entire application lifetime.")] public static IAppBuilder UseAutofacWebApi(this IAppBuilder app, HttpConfiguration configuration) { if (app == null) { - throw new ArgumentNullException("app"); + throw new ArgumentNullException(nameof(app)); } if (configuration == null) { - throw new ArgumentNullException("configuration"); + throw new ArgumentNullException(nameof(configuration)); } if (!configuration.MessageHandlers.OfType().Any()) diff --git a/src/Autofac.Integration.WebApi.Owin/DependencyScopeHandler.cs b/src/Autofac.Integration.WebApi.Owin/DependencyScopeHandler.cs index 8d21a60..bac0030 100644 --- a/src/Autofac.Integration.WebApi.Owin/DependencyScopeHandler.cs +++ b/src/Autofac.Integration.WebApi.Owin/DependencyScopeHandler.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Autofac Project. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Security; @@ -9,20 +12,37 @@ namespace Autofac.Integration.WebApi.Owin { + /// + /// Delegating handler that manages coordinating the OWIN request lifetime with the Web API request lifetime. + /// [SecurityCritical] - class DependencyScopeHandler : DelegatingHandler + internal class DependencyScopeHandler : DelegatingHandler { + /// + /// Assigns the OWIN request lifetime scope to the Web API request lifetime scope. + /// + /// The HTTP request message to send to the server. + /// A cancellation token to cancel the operation. + /// The task object representing the asynchronous operation. [SecuritySafeCritical] - [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { - if (request == null) throw new ArgumentNullException("request"); + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } var owinContext = request.GetOwinContext(); - if (owinContext == null) return base.SendAsync(request, cancellationToken); + if (owinContext == null) + { + return base.SendAsync(request, cancellationToken); + } var lifetimeScope = owinContext.GetAutofacLifetimeScope(); - if (lifetimeScope == null) return base.SendAsync(request, cancellationToken); + if (lifetimeScope == null) + { + return base.SendAsync(request, cancellationToken); + } var dependencyScope = new AutofacWebApiDependencyScope(lifetimeScope); request.Properties[HttpPropertyKeys.DependencyScope] = dependencyScope; diff --git a/src/Autofac.Integration.WebApi.Owin/Properties/AssemblyInfo.cs b/src/Autofac.Integration.WebApi.Owin/Properties/AssemblyInfo.cs index 416790a..eef849b 100644 --- a/src/Autofac.Integration.WebApi.Owin/Properties/AssemblyInfo.cs +++ b/src/Autofac.Integration.WebApi.Owin/Properties/AssemblyInfo.cs @@ -1,21 +1,10 @@ -using System; -using System.Reflection; -using System.Resources; +// Copyright (c) Autofac Project. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -[assembly: AssemblyTitle("Autofac.Integration.WebApi.Owin")] [assembly: InternalsVisibleTo("Autofac.Integration.WebApi.Owin.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001008728425885ef385e049261b18878327dfaaf0d666dea3bd2b0e4f18b33929ad4e5fbc9087e7eda3c1291d2de579206d9b4292456abffbe8be6c7060b36da0c33b883e3878eaf7c89fddf29e6e27d24588e81e86f3a22dd7b1a296b5f06fbfb500bbd7410faa7213ef4e2ce7622aefc03169b0324bcd30ccfe9ac8204e4960be6")] [assembly: ComVisible(false)] -[assembly: CLSCompliant(true)] -[assembly: AssemblyCompany("Autofac Project - https://autofac.org")] -[assembly: AssemblyProduct("Autofac")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] -[assembly: AssemblyVersion("0.0.0.0")] -[assembly: AssemblyFileVersion("0.0.0.0")] -[assembly: AssemblyInformationalVersion("0.0.0")] -[assembly: AssemblyConfiguration("Release")] -[assembly: AssemblyCopyright("Copyright © 2014 Autofac Contributors")] -[assembly: AssemblyDescription("Autofac Web API OWIN Integration")] \ No newline at end of file +[assembly: CLSCompliant(false)] diff --git a/src/Autofac.Integration.WebApi.Owin/app.config b/src/Autofac.Integration.WebApi.Owin/app.config deleted file mode 100644 index 81e81a2..0000000 --- a/src/Autofac.Integration.WebApi.Owin/app.config +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/Autofac.Integration.WebApi.Owin.Test/App.config b/test/Autofac.Integration.WebApi.Owin.Test/App.config deleted file mode 100644 index 1eae6d8..0000000 --- a/test/Autofac.Integration.WebApi.Owin.Test/App.config +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/Autofac.Integration.WebApi.Owin.Test/Autofac.Integration.WebApi.Owin.Test.csproj b/test/Autofac.Integration.WebApi.Owin.Test/Autofac.Integration.WebApi.Owin.Test.csproj index 61cddeb..42718d6 100644 --- a/test/Autofac.Integration.WebApi.Owin.Test/Autofac.Integration.WebApi.Owin.Test.csproj +++ b/test/Autofac.Integration.WebApi.Owin.Test/Autofac.Integration.WebApi.Owin.Test.csproj @@ -1,99 +1,21 @@ - - - - - Debug - AnyCPU - {2EF2FBB2-77D0-4D85-936E-5A00881CF5F6} - Library - Properties - Autofac.Integration.WebApi.Owin.Test - Autofac.Integration.WebApi.Owin.Test - v4.6.1 - 512 - ..\..\..\ - true - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - + + net472 true - - ..\..\Autofac.snk - - - - - - - - - - - - - {1a3e68cf-e1d5-4e30-96c3-9b8687df9283} - Autofac.Integration.WebApi.Owin - + - - - - - - - - 5.0.0 - - - 5.0.1 - - - 5.0.0 - - - 5.2.0 - - - 5.0.8 - - - 2.1.0 - - - 2.1.0 + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - 2.1.0 + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - \ No newline at end of file diff --git a/test/Autofac.Integration.WebApi.Owin.Test/AutofacWebApiAppBuilderExtensionsFixture.cs b/test/Autofac.Integration.WebApi.Owin.Test/AutofacWebApiAppBuilderExtensionsFixture.cs index 1d0ca21..5cf3275 100644 --- a/test/Autofac.Integration.WebApi.Owin.Test/AutofacWebApiAppBuilderExtensionsFixture.cs +++ b/test/Autofac.Integration.WebApi.Owin.Test/AutofacWebApiAppBuilderExtensionsFixture.cs @@ -16,7 +16,7 @@ public void UseAutofacWebApiAddsDelegatingHandler() app.UseAutofacWebApi(configuration); - Assert.Equal(1, configuration.MessageHandlers.OfType().Count()); + Assert.Single(configuration.MessageHandlers.OfType()); } [Fact] @@ -28,7 +28,7 @@ public void UseAutofacWebApiWillOnlyAddDelegatingHandlerOnce() app.UseAutofacWebApi(configuration); app.UseAutofacWebApi(configuration); - Assert.Equal(1, configuration.MessageHandlers.OfType().Count()); + Assert.Single(configuration.MessageHandlers.OfType()); } } -} \ No newline at end of file +} diff --git a/test/Autofac.Integration.WebApi.Owin.Test/Properties/AssemblyInfo.cs b/test/Autofac.Integration.WebApi.Owin.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index 6c94b2e..0000000 --- a/test/Autofac.Integration.WebApi.Owin.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Reflection; - -[assembly: AssemblyTitle("Autofac.Integration.WebApi.Owin.Test")]