Skip to content

Commit bcc9f91

Browse files
authored
Merge pull request #30 from autofac/feature/vscode-build
Build with .NET 6, enable VS Code, update min Autofac
2 parents bc69438 + 701a42b commit bcc9f91

39 files changed

+1845
-1639
lines changed

.editorconfig

Lines changed: 199 additions & 198 deletions
Large diffs are not rendered by default.

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"cSpell.words": [
3+
"autofac",
4+
"cref",
5+
"inheritdoc",
6+
"langword",
7+
"paramref",
8+
"seealso",
9+
"typeparam",
10+
"unmanaged",
11+
"xunit"
12+
],
13+
"dotnet-test-explorer.runInParallel": true,
14+
"dotnet-test-explorer.testProjectPath": "test/**/*.Test.csproj"
15+
}

.vscode/tasks.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"tasks": [
3+
{
4+
"args": [
5+
"build",
6+
"${workspaceFolder}/Autofac.Wcf.sln",
7+
"/property:GenerateFullPaths=true",
8+
"/consoleloggerparameters:NoSummary"
9+
],
10+
"command": "dotnet",
11+
"group": {
12+
"isDefault": true,
13+
"kind": "build"
14+
},
15+
"label": "build",
16+
"problemMatcher": "$msCompile",
17+
"type": "process"
18+
}
19+
],
20+
"version": "2.0.0"
21+
}

NuGet.Config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<packageSources>
44
<clear />
55
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
6-
<add key="Xunit MyGet" value="https://myget.org/F/xunit/api/v3/index.json" protocolVersion="3" />
76
<add key="Autofac MyGet" value="https://www.myget.org/F/autofac/api/v3/index.json" protocolVersion="3" />
87
</packageSources>
98
<disabledPackageSources>

README.md

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,92 @@
22

33
Windows Communication Foundation (WCF) integration for [Autofac](https://autofac.org).
44

5-
[![Build status](https://ci.appveyor.com/api/projects/status/5hf5l1qqncrc15yu?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-yirkj) [![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/autofac/Autofac.Wcf)
5+
[![Build status](https://ci.appveyor.com/api/projects/status/5hf5l1qqncrc15yu?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-yirkj)
66

7-
Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
7+
Please file issues and pull requests for this package [in this repository](https://github.com/autofac/Autofac.Wcf/issues) rather than in the Autofac core repo.
88

99
- [Documentation](https://autofac.readthedocs.io/en/latest/integration/wcf.html)
1010
- [NuGet](https://www.nuget.org/packages/Autofac.Wcf/)
1111
- [Contributing](https://autofac.readthedocs.io/en/latest/contributors.html)
12+
- [Open in Visual Studio Code](https://open.vscode.dev/autofac/Autofac.Wcf)
13+
14+
## Quick Start: Clients
15+
16+
During application startup, for each service register a `ChannelFactory<T>` and a function that uses the factory to open channels:
17+
18+
```c#
19+
var builder = new ContainerBuilder();
20+
21+
// Register the channel factory for the service. Make it
22+
// SingleInstance since you don't need a new one each time.
23+
builder
24+
.Register(c => new ChannelFactory<ITrackListing>(
25+
new BasicHttpBinding(),
26+
new EndpointAddress("http://localhost/TrackListingService")))
27+
.SingleInstance();
28+
29+
// Register the service interface using a lambda that creates
30+
// a channel from the factory. Include the UseWcfSafeRelease()
31+
// helper to handle proper disposal.
32+
builder
33+
.Register(c => c.Resolve<ChannelFactory<ITrackListing>>().CreateChannel())
34+
.As<ITrackListing>()
35+
.UseWcfSafeRelease();
36+
37+
// You can also register other dependencies.
38+
builder.RegisterType<AlbumPrinter>();
39+
40+
var container = builder.Build();
41+
```
42+
43+
When consuming the service, add a constructor dependency as normal. This example shows an application that prints a track listing to the console using the remote `ITrackListing` service. It does this via the `AlbumPrinter` class:
44+
45+
```c#
46+
public class AlbumPrinter
47+
{
48+
readonly ITrackListing _trackListing;
49+
50+
public AlbumPrinter(ITrackListing trackListing)
51+
{
52+
_trackListing = trackListing;
53+
}
54+
55+
public void PrintTracks(string artist, string album)
56+
{
57+
foreach (var track in _trackListing.GetTracks(artist, album))
58+
Console.WriteLine("{0} - {1}", track.Position, track.Title);
59+
}
60+
}
61+
```
62+
63+
## Quick Start: Services
64+
65+
To get Autofac integrated with WCF on the service side you need to reference the WCF integration NuGet package, register your services, and set the dependency resolver. You also need to update your .svc files to reference the Autofac service host factory.
66+
67+
Here’s a sample application startup block:
68+
69+
```c#
70+
protected void Application_Start()
71+
{
72+
var builder = new ContainerBuilder();
73+
74+
// Register your service implementations.
75+
builder.RegisterType<TestService.Service1>();
76+
77+
// Set the dependency resolver.
78+
var container = builder.Build();
79+
AutofacHostFactory.Container = container;
80+
}
81+
```
82+
83+
And here’s a sample .svc file.
84+
85+
```aspx
86+
<%@ ServiceHost
87+
Service="TestService.Service1, TestService"
88+
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
89+
```
90+
91+
## Get Help
92+
93+
**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).

appveyor.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
version: 6.0.0.{build}
1+
image: Visual Studio 2022
2+
3+
version: 6.1.0.{build}
24

35
dotnet_csproj:
4-
version_prefix: '6.0.0'
6+
version_prefix: '6.1.0'
57
patch: true
68
file: 'src\**\*.csproj'
79

810
configuration: Release
911

10-
image: Visual Studio 2019
11-
1212
environment:
1313
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1414
NUGET_XMLDOC_MODE: skip
@@ -20,20 +20,20 @@ nuget:
2020

2121
clone_depth: 1
2222

23-
test: off
23+
test: false
2424

2525
build_script:
26-
- ps: .\build.ps1
26+
- pwsh: .\build.ps1
2727

2828
artifacts:
29-
- path: artifacts\packages\**\*.nupkg
30-
name: MyGet
29+
- path: artifacts\packages\**\*.*nupkg
30+
name: MyGet
31+
type: NuGetPackage
3132

3233
deploy:
33-
- provider: NuGet
34-
server: https://www.myget.org/F/autofac/api/v2/package
35-
api_key:
36-
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
37-
skip_symbols: true
38-
symbol_server: https://www.myget.org/F/autofac/symbols/api/v2/package
39-
artifact: MyGet
34+
- provider: NuGet
35+
server: https://www.myget.org/F/autofac/api/v2/package
36+
symbol_server: https://www.myget.org/F/autofac/api/v2/package
37+
api_key:
38+
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
39+
artifact: MyGet

build.ps1

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,61 @@
33
########################
44

55
Push-Location $PSScriptRoot
6-
Import-Module $PSScriptRoot\Build\Autofac.Build.psd1 -Force
6+
try {
7+
Import-Module $PSScriptRoot/build/Autofac.Build.psd1 -Force
78

8-
$artifactsPath = "$PSScriptRoot\artifacts"
9-
$packagesPath = "$artifactsPath\packages"
10-
$sdkVersion = (Get-Content "$PSScriptRoot\global.json" | ConvertFrom-Json).sdk.version
9+
$artifactsPath = "$PSScriptRoot/artifacts"
10+
$packagesPath = "$artifactsPath/packages"
1111

12-
# Clean up artifacts folder
13-
if (Test-Path $artifactsPath) {
14-
Write-Message "Cleaning $artifactsPath folder"
15-
Remove-Item $artifactsPath -Force -Recurse
16-
}
12+
$globalJson = (Get-Content "$PSScriptRoot/global.json" | ConvertFrom-Json -NoEnumerate);
13+
14+
$sdkVersion = $globalJson.sdk.version
15+
16+
# Clean up artifacts folder
17+
if (Test-Path $artifactsPath) {
18+
Write-Message "Cleaning $artifactsPath folder"
19+
Remove-Item $artifactsPath -Force -Recurse
20+
}
1721

18-
# Install dotnet CLI
19-
Write-Message "Installing .NET Core SDK version $sdkVersion"
20-
Install-DotNetCli -Version $sdkVersion
22+
# Install dotnet SDK versions during CI. In a local build we assume you have
23+
# everything installed; on CI we'll force the install. If you install _any_
24+
# SDKs, you have to install _all_ of them because you can't install SDKs in
25+
# two different locations. dotnet CLI locates SDKs relative to the
26+
# executable.
27+
if ($Null -ne $env:APPVEYOR_BUILD_NUMBER) {
28+
Install-DotNetCli -Version $sdkVersion
29+
foreach ($additional in $globalJson.additionalSdks)
30+
{
31+
Install-DotNetCli -Version $additional;
32+
}
33+
}
2134

22-
# Write out dotnet information
23-
& dotnet --info
35+
# Write out dotnet information
36+
& dotnet --info
2437

25-
# Set version suffix
26-
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
27-
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
28-
$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
38+
# Set version suffix
39+
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
40+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
41+
$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)).Replace('/', '-'))-$revision" }[$branch -eq "master" -and $revision -ne "local"]
2942

30-
Write-Message "Package version suffix is '$versionSuffix'"
43+
Write-Message "Package version suffix is '$versionSuffix'"
3144

32-
# Package restore
33-
Write-Message "Restoring packages"
34-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages
45+
# Package restore
46+
Write-Message "Restoring packages"
47+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages
3548

36-
# Build/package
37-
Write-Message "Building projects and packages"
38-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix
49+
# Build/package
50+
Write-Message "Building projects and packages"
51+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix
3952

40-
# Test
41-
Write-Message "Executing unit tests"
42-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Invoke-Test
53+
# Test
54+
Write-Message "Executing unit tests"
55+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Invoke-Test
4356

44-
# Finished
45-
Write-Message "Build finished"
46-
Pop-Location
57+
58+
# Finished
59+
Write-Message "Build finished"
60+
}
61+
finally {
62+
Pop-Location
63+
}

build/Analyzers.ruleset

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
<Rule Id="SA1309" Action="None" />
3535
<!-- Suppressions must have a justification -->
3636
<Rule Id="SA1404" Action="None" />
37-
<!-- Use trailing comma in initializers - lots of false positives for enums in StyleCop 1.1.0-beta004 -->
38-
<Rule Id="SA1413" Action="None" />
39-
<!-- Parameter documentation mus be in the right order -->
37+
<!-- Parameter documentation must be in the right order -->
4038
<Rule Id="SA1612" Action="None" />
4139
<!-- Return value must be documented -->
4240
<Rule Id="SA1615" Action="None" />
@@ -46,8 +44,6 @@
4644
<Rule Id="SA1625" Action="None" />
4745
<!-- Exception documentation must not be empty -->
4846
<Rule Id="SA1627" Action="None" />
49-
<!-- File must have header -->
50-
<Rule Id="SA1633" Action="None" />
5147
<!-- Enable XML documentation output-->
5248
<Rule Id="SA1652" Action="None" />
5349
</Rules>

build/Autofac.Build.psm1

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@ function Install-DotNetCli {
3434
[string]
3535
$Version = "Latest"
3636
)
37-
38-
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue)) {
39-
$installedVersion = dotnet --version
40-
if ($installedVersion -eq $Version) {
41-
Write-Message ".NET Core SDK version $Version is already installed"
42-
return;
43-
}
44-
}
37+
Write-Message "Installing .NET SDK version $Version"
4538

4639
$callerPath = Split-Path $MyInvocation.PSCommandPath
4740
$installDir = Join-Path -Path $callerPath -ChildPath ".dotnet/cli"
@@ -56,15 +49,43 @@ function Install-DotNetCli {
5649
}
5750

5851
& ./.dotnet/dotnet-install.ps1 -InstallDir "$installDir" -Version $Version
59-
$env:PATH = "$installDir;$env:PATH"
6052
} else {
6153
if (!(Test-Path ./.dotnet/dotnet-install.sh)) {
6254
Invoke-WebRequest "https://dot.net/v1/dotnet-install.sh" -OutFile "./.dotnet/dotnet-install.sh"
6355
}
6456

6557
& bash ./.dotnet/dotnet-install.sh --install-dir "$installDir" --version $Version
66-
$env:PATH = "$installDir`:$env:PATH"
6758
}
59+
60+
Add-Path "$installDir"
61+
}
62+
63+
<#
64+
.SYNOPSIS
65+
Appends a given value to the path but only if the value does not yet exist within the path.
66+
.PARAMETER Path
67+
The path to append.
68+
#>
69+
function Add-Path {
70+
[CmdletBinding()]
71+
Param(
72+
[ValidateNotNullOrEmpty()]
73+
[string]
74+
$Path
75+
)
76+
77+
$pathSeparator = ":";
78+
79+
if ($IsWindows) {
80+
$pathSeparator = ";";
81+
}
82+
83+
$pathValues = $env:PATH.Split($pathSeparator);
84+
if ($pathValues -Contains $Path) {
85+
return;
86+
}
87+
88+
$env:PATH = "${Path}${pathSeparator}$env:PATH"
6889
}
6990

7091
<#
@@ -175,8 +196,7 @@ function Invoke-Test {
175196
--configuration Release `
176197
--logger:trx `
177198
/p:CollectCoverage=true `
178-
/p:CoverletOutput="..\..\" `
179-
/p:MergeWith="..\..\coverage.json" `
199+
/p:CoverletOutput="../../artifacts/coverage/$($Project.Name)/" `
180200
/p:CoverletOutputFormat="json%2clcov" `
181201
/p:ExcludeByAttribute=CompilerGeneratedAttribute `
182202
/p:ExcludeByAttribute=GeneratedCodeAttribute

0 commit comments

Comments
 (0)