Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
397 changes: 199 additions & 198 deletions .editorconfig

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"cSpell.words": [
"autofac",
"cref",
"inheritdoc",
"langword",
"notnull",
"paramref",
"seealso",
"typeparam",
"unmanaged",
"xunit"
],
"dotnet-test-explorer.runInParallel": true,
Expand Down
11 changes: 0 additions & 11 deletions ISSUE_TEMPLATE.md

This file was deleted.

4 changes: 2 additions & 2 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration>
<packageSources>
<clear />
<add key="Autofac MyGet" value="https://www.myget.org/F/autofac/api/v2" />
<add key="NuGet v3" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Autofac MyGet" value="https://www.myget.org/F/autofac/api/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,44 @@

ASP.NET Web API integration for [Autofac](https://autofac.org).

[![Build status](https://ci.appveyor.com/api/projects/status/i7fjrapyswrvy73r?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-webapi) [![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/autofac/Autofac.WebApi)
[![Build status](https://ci.appveyor.com/api/projects/status/i7fjrapyswrvy73r?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-webapi)

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

- [Documentation](https://autofac.readthedocs.io/en/latest/integration/webapi.html)
- [NuGet](https://www.nuget.org/packages/Autofac.WebApi2/)
- [Contributing](https://autofac.readthedocs.io/en/latest/contributors.html)
- [Open in Visual Studio Code](https://open.vscode.dev/autofac/Autofac.WebApi)

## Quick Start

To get Autofac integrated with Web API you need to reference the Web API integration NuGet package, register your controllers, and set the dependency resolver. You can optionally enable other features as well.

```c#
protected void Application_Start()
{
var builder = new ContainerBuilder();

// Get your HttpConfiguration.
var config = GlobalConfiguration.Configuration;

// Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

// OPTIONAL: Register the Autofac filter provider.
builder.RegisterWebApiFilterProvider(config);

// OPTIONAL: Register the Autofac model binder provider.
builder.RegisterWebApiModelBinderProvider();

// Set the dependency resolver to be Autofac.
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
```

[Check out the documentation](https://autofac.readthedocs.io/en/latest/integration/webapi.html) for more usage details.

## Get Help

**Need help with Autofac?** We have [a documentation site](https://autofac.readthedocs.io/) as well as [API documentation](https://autofac.org/apidoc/). We're ready to answer your questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/autofac) or check out the [discussion forum](https://groups.google.com/forum/#forum/autofac).
22 changes: 12 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
image: Visual Studio 2022

version: 6.1.0.{build}

dotnet_csproj:
Expand All @@ -7,8 +9,6 @@ dotnet_csproj:

configuration: Release

image: Visual Studio 2022

environment:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
NUGET_XMLDOC_MODE: skip
Expand All @@ -23,15 +23,17 @@ clone_depth: 1
test: false

build_script:
- pwsh: .\build.ps1
- pwsh: .\build.ps1

artifacts:
- path: artifacts\packages\**\*.nupkg
name: MyGet
- path: artifacts\packages\**\*.*nupkg
name: MyGet
type: NuGetPackage

deploy:
- provider: NuGet
server: https://www.myget.org/F/autofac/
api_key:
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
symbol_server: https://nuget.symbolsource.org/MyGet/autofac
- provider: NuGet
server: https://www.myget.org/F/autofac/api/v2/package
symbol_server: https://www.myget.org/F/autofac/api/v2/package
api_key:
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
artifact: MyGet
17 changes: 11 additions & 6 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ try {
Remove-Item $artifactsPath -Force -Recurse
}

# Install dotnet CLI
Install-DotNetCli -Version $sdkVersion

foreach ($additional in $globalJson.additionalSdks)
{
Install-DotNetCli -Version $additional;
# Install dotnet SDK versions during CI. In a local build we assume you have
# everything installed; on CI we'll force the install. If you install _any_
# SDKs, you have to install _all_ of them because you can't install SDKs in
# two different locations. dotnet CLI locates SDKs relative to the
# executable.
if ($Null -ne $env:APPVEYOR_BUILD_NUMBER) {
Install-DotNetCli -Version $sdkVersion
foreach ($additional in $globalJson.additionalSdks)
{
Install-DotNetCli -Version $additional;
}
}

# Write out dotnet information
Expand Down
68 changes: 34 additions & 34 deletions build/Autofac.Build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# 4: dotnet / NuGet package restore failure

<#
.SYNOPSIS
Gets the set of directories in which projects are available for compile/processing.
.SYNOPSIS
Gets the set of directories in which projects are available for compile/processing.

.PARAMETER RootPath
Path where searching for project directories should begin.
.PARAMETER RootPath
Path where searching for project directories should begin.
#>
function Get-DotNetProjectDirectory {
[CmdletBinding()]
Expand Down Expand Up @@ -115,39 +115,39 @@ function Invoke-DotNetBuild {
}

<#
.SYNOPSIS
Invokes the dotnet utility to package a project.
.SYNOPSIS
Invokes the dotnet utility to package a project.

.PARAMETER ProjectDirectory
Path to the directory containing the project to package.
.PARAMETER ProjectDirectory
Path to the directory containing the project to package.

.PARAMETER PackagesPath
Path to the "artifacts/packages" folder where packages should go.
.PARAMETER PackagesPath
Path to the "artifacts/packages" folder where packages should go.

.PARAMETER VersionSuffix
The version suffix to use for the NuGet package version.
.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,
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNull()]
[System.IO.DirectoryInfo[]]
$ProjectDirectory,

[Parameter(Mandatory = $True, ValueFromPipeline = $False)]
[AllowEmptyString()]
[string]
$VersionSuffix
)
Begin {
New-Item -Path $PackagesPath -ItemType Directory -Force | Out-Null
}
[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 "") {
Expand Down Expand Up @@ -212,11 +212,11 @@ function Invoke-Test {
}

<#
.SYNOPSIS
Restores dependencies using the dotnet utility.
.SYNOPSIS
Restores dependencies using the dotnet utility.

.PARAMETER ProjectDirectory
Path to the directory containing the project with dependencies to restore.
.PARAMETER ProjectDirectory
Path to the directory containing the project with dependencies to restore.
#>
function Restore-DependencyPackages {
[CmdletBinding()]
Expand Down
47 changes: 0 additions & 47 deletions build/CodeAnalysisDictionary.xml

This file was deleted.

64 changes: 64 additions & 0 deletions build/Test.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
<Rule Id="CA1032" Action="None" />
<!-- Change names to avoid reserved word overlaps (e.g., Delegate, GetType, etc.) - too many of these in the public API, we'd break if we fixed it. -->
<Rule Id="CA1716" Action="None" />
<!-- Change Dispose() to call GC.SuppressFinalize - in tests we don't really care and it can impact readability. -->
<Rule Id="CA1816" Action="None" />
<!-- Mark members static - test methods may not access member data but also can't be static. -->
<Rule Id="CA1822" Action="None" />
<!-- Implement serialization constructors - false positive when building .NET Core -->
<Rule Id="CA2229" Action="None" />
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
<Rule Id="CA2237" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<!-- Prefix local calls with this -->
<Rule Id="SA1101" Action="None" />
<!-- Use built-in type alias -->
<Rule Id="SA1121" Action="None" />
<!-- Use String.Empty instead of "" -->
<Rule Id="SA1122" Action="None" />
<!-- Using statements must be inside a namespace -->
<Rule Id="SA1200" Action="None" />
<!-- Enforce order of class members by member type -->
<Rule Id="SA1201" Action="None" />
<!-- Enforce order of class members by member visibility -->
<Rule Id="SA1202" Action="None" />
<!-- Enforce order of constantand static members -->
<Rule Id="SA1203" Action="None" />
<!-- Enforce order of static vs. non-static members -->
<Rule Id="SA1204" Action="None" />
<!-- Enforce order of readonly vs. non-readonly members -->
<Rule Id="SA1214" Action="None" />
<!-- Fields can't start with underscore -->
<Rule Id="SA1309" Action="None" />
<!-- Suppressions must have a justification -->
<Rule Id="SA1404" Action="None" />
<!-- Elements should be documented -->
<Rule Id="SA1600" Action="None" />
<!-- Enuemration items should be documented -->
<Rule Id="SA1602" Action="None" />
<!-- Parameter documentation must be in the right order -->
<Rule Id="SA1612" Action="None" />
<!-- Return value must be documented -->
<Rule Id="SA1615" Action="None" />
<!-- Generic type parameters must be documented -->
<Rule Id="SA1618" Action="None" />
<!-- Don't copy/paste documentation -->
<Rule Id="SA1625" Action="None" />
<!-- Exception documentation must not be empty -->
<Rule Id="SA1627" Action="None" />
<!-- Enable XML documentation output-->
<Rule Id="SA1652" Action="None" />
<!-- Private member is unused - tests for reflection require members that may not get used. -->
<Rule Id="IDE0051" Action="None" />
<!-- Private member assigned value never read - tests for reflection require values that may not get used. -->
<Rule Id="IDE0052" Action="None" />
<!-- Remove unused parameter - tests for reflection require parameters that may not get used. -->
<Rule Id="IDE0060" Action="None" />
</Rules>
</RuleSet>
8 changes: 4 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"rollForward": "latestFeature"
}
"sdk": {
"rollForward": "latestFeature",
"version": "6.0.301"
}
}
Loading