Skip to content

Commit ef2b36b

Browse files
mjacobs80AGiorgettialkampfergit
authored
Merged PR for .NET 8 support
* Refs: castleproject#646 Castle.Windsor.Extension.DepencencyInjection removed null check on scope cache (AsyncLocal can be null on Threads coming from Threadpool.UnsafeQueueUserWorkItem, having no null check was also the original behavior) * ExtensionContainerRootsScopeAccessor might return a null root scope in Threadpool.UnsafeQueueUserWorkItem. * Added More failing test cases * Added Threadpool.Unsafe... failing tests, added comments on critical files * Improved tests and comments * Option to map custom NetStatic to Castle Singleton lifestyle. this improve resolution of singleton object that might not need a root scope, the windsor container should be enough to resolve singletons * RootScope AsyncLocal cache can be null when AspNetCore tries to create scopes from Threadpool.UnsafeQueueUserWorkItem * Improved Tests showing supported, unsupported and memory leaks scenarios * Added comments on WindsorScopedServiceProvider dispose * Updated Castle.Windsor reference to nuget package to create private deploy packages * Added NuGet package build instructions * added gitversion * Update to work with .NET 8 dependency registration. Major fix was to support keyed registration scenario * Fixed bug in missing root scope with orleans/kestrel. The previous handling of root scope is wrong, the code set root scope in an AsyncLocal variable when WindsorServiceProviderFactoryBase was first creatd. The problem arise with kestrel or orleans in .NET 8, they use a Thread Pool that runs code outside AsyncLocal so it will break resolution. It was not possible to reproduce locally, but it was reproduced with production code. A repro for the bug still missing. Also we can support using a Global root scope only if we use only ONE CONTAINER in the .NET core DI, because basic structure does not allow to find the container that is resolving scoped component thus we cannot determin the right root context. Still work to do to support multiple container. * Added logic to support multiple container in .NET 8 DI Needed to modify basic Castle.Winsor library to support the ability from IHandler interface to get the current kernel associated with the handler. This is needed to find the correct root scope associated with that kernel instance. * Changed constants in keyedregistration helper. * Updated nuget test adapter fixed a resolution bug The bug happened when you register a service with one NON keyed component then again with KEYED components. The adapter incorrectly checked only the first returned service for KEYED and returns null. Identified after update to Orleans 8.1.0 * Fixed IsDefault() usage in DependencyInjectionAdapter If multiple concrete classes are registered in castle, when you resolve castle resolves the first one. With Microsoft DI is the oposite, you want the last registered. The resolution is now fixed to honor IsDefault() because previous code registered every component with IsDefault() if it is registered from the adapter. * Fixed (again) resolution rules during resolve. We added a new concept, an extendede property that allows the code to understand if the dependency was registered through the adapter (ServiceCollection) or directly through the Container. This allows us to change the resolution rule in case of multiple services registered with the same name. * Cleanup from PR Requests * Remove wrong disposal of container --------- Co-authored-by: Alessandro Giorgetti <[email protected]> Co-authored-by: Gian Maria Ricci <[email protected]>
1 parent 77216d1 commit ef2b36b

File tree

49 files changed

+2484
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2484
-114
lines changed

.config/GitVersion.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
branches: {}
2+
ignore:
3+
sha: []
4+
merge-message-formats: {}
5+
mode: ContinuousDeployment

.config/dotnet-tools.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"nswag.consolecore": {
6+
"version": "14.0.0",
7+
"commands": [
8+
"nswag"
9+
]
10+
},
11+
"gitversion.tool": {
12+
"version": "5.2.4",
13+
"commands": [
14+
"dotnet-gitversion"
15+
]
16+
}
17+
}
18+
}

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ indent_size = 2
1010
[*.cs]
1111
indent_style = tab
1212
indent_size = 4
13+
csharp_new_line_before_open_brace = all

.vscode/tasks.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
2-
"version": "0.1.0",
2+
"version": "2.0.0",
33
"command": "dotnet",
4-
"isShellCommand": true,
54
"args": [],
65
"tasks": [
76
{
8-
"taskName": "build",
7+
"label": "build",
8+
"type": "shell",
9+
"command": "dotnet",
910
"args": [
11+
"build",
1012
"${workspaceRoot}/src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj"
1113
],
12-
"isBuildCommand": true,
13-
"problemMatcher": "$msCompile"
14+
"problemMatcher": "$msCompile",
15+
"group": {
16+
"_id": "build",
17+
"isDefault": false
18+
}
1419
}
1520
]
1621
}

.vscode/tasks.json.old

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.1.0",
3+
"command": "dotnet",
4+
"isShellCommand": true,
5+
"args": [],
6+
"tasks": [
7+
{
8+
"taskName": "build",
9+
"args": [
10+
"${workspaceRoot}/src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj"
11+
],
12+
"isBuildCommand": true,
13+
"problemMatcher": "$msCompile"
14+
}
15+
]
16+
}

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ Castle Windsor is a best of breed, mature Inversion of Control container availab
66

77
See the [documentation](docs/README.md).
88

9+
## Considerations
10+
11+
Castle.Windsor.Extensions.DependencyInjection try to make Microsoft Dependency Injection works with Castle.Windsor. We have some
12+
really different rules in the two world, one is the order of resolution exposed by the test Resolve_order_in_castle that shows
13+
how the two have two different strategies.
14+
15+
1. Microsof DI want to resolve the last registered service
16+
2. Castle.Windsor want to resolve the first registered service.
17+
18+
This is one of the point where the integration become painful, because it can happen that the very same service got resolved
19+
in two distinct way, depending on who is resolving the service.
20+
21+
The preferred solution is to understand who is registering the service and resolve everything accordingly.
22+
23+
## I want to try everything locally.
24+
25+
If you want to easily try a local compiled version on your project you can use the following trick.
26+
27+
1. Add the GenerateAssemblyInfo to false on the project file
28+
1. Add an assemblyinfo.cs in Properties folder and add the [assembly: AssemblyVersion("6.0.0")] attribute to force the correct version
29+
1. Compile the project
30+
1. Copy into the local nuget cache, from the output folder of this project run
31+
32+
```
33+
copy * %Uer Profile%\.nuget\packages\castle.windsor.extensions.dependencyinjection\6.0.x\lib\net8.0
34+
```
35+
36+
This usually works.
37+
938
## Releases
1039

1140
See the [releases](https://github.com/castleproject/Windsor/releases).

build_without_wcf_tests.cmd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@ECHO OFF
2+
REM ****************************************************************************
3+
REM Copyright 2004-2013 Castle Project - http://www.castleproject.org/
4+
REM Licensed under the Apache License, Version 2.0 (the "License");
5+
REM you may not use this file except in compliance with the License.
6+
REM You may obtain a copy of the License at
7+
REM
8+
REM http://www.apache.org/licenses/LICENSE-2.0
9+
REM
10+
REM Unless required by applicable law or agreed to in writing, software
11+
REM distributed under the License is distributed on an "AS IS" BASIS,
12+
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
REM See the License for the specific language governing permissions and
14+
REM limitations under the License.
15+
REM ****************************************************************************
16+
17+
@call buildscripts\build_without_wcf_tests.cmd %*
18+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
@ECHO OFF
2+
REM ****************************************************************************
3+
REM Copyright 2004-2013 Castle Project - http://www.castleproject.org/
4+
REM Licensed under the Apache License, Version 2.0 (the "License");
5+
REM you may not use this file except in compliance with the License.
6+
REM You may obtain a copy of the License at
7+
REM
8+
REM http://www.apache.org/licenses/LICENSE-2.0
9+
REM
10+
REM Unless required by applicable law or agreed to in writing, software
11+
REM distributed under the License is distributed on an "AS IS" BASIS,
12+
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
REM See the License for the specific language governing permissions and
14+
REM limitations under the License.
15+
REM ****************************************************************************
16+
17+
if "%1" == "" goto no_config
18+
if "%1" NEQ "" goto set_config
19+
20+
:set_config
21+
SET Configuration=%1
22+
GOTO restore_packages
23+
24+
:no_config
25+
SET Configuration=Release
26+
GOTO restore_packages
27+
28+
:restore_packages
29+
dotnet restore ./tools/Explicit.NuGet.Versions/Explicit.NuGet.Versions.csproj
30+
dotnet restore ./buildscripts/BuildScripts.csproj
31+
dotnet restore ./src/Castle.Windsor/Castle.Windsor.csproj
32+
dotnet restore ./src/Castle.Facilities.Logging/Castle.Facilities.Logging.csproj
33+
dotnet restore ./src/Castle.Facilities.AspNet.SystemWeb/Castle.Facilities.AspNet.SystemWeb.csproj
34+
dotnet restore ./src/Castle.Facilities.AspNet.SystemWeb.Tests/Castle.Facilities.AspNet.SystemWeb.Tests.csproj
35+
dotnet restore ./src/Castle.Facilities.AspNet.Mvc/Castle.Facilities.AspNet.Mvc.csproj
36+
dotnet restore ./src/Castle.Facilities.AspNet.Mvc.Tests/Castle.Facilities.AspNet.Mvc.Tests.csproj
37+
dotnet restore ./src/Castle.Facilities.AspNet.WebApi/Castle.Facilities.AspNet.WebApi.csproj
38+
dotnet restore ./src/Castle.Facilities.AspNet.WebApi.Tests/Castle.Facilities.AspNet.WebApi.Tests.csproj
39+
dotnet restore ./src/Castle.Facilities.AspNetCore/Castle.Facilities.AspNetCore.csproj
40+
dotnet restore ./src/Castle.Facilities.AspNetCore.Tests/Castle.Facilities.AspNetCore.Tests.csproj
41+
dotnet restore ./src/Castle.Windsor.Extensions.DependencyInjection.Tests/Castle.Windsor.Extensions.DependencyInjection.Tests.csproj
42+
dotnet restore ./src/Castle.Windsor.Extensions.DependencyInjection/Castle.Windsor.Extensions.DependencyInjection.csproj
43+
dotnet restore ./src/Castle.Windsor.Extensions.Hosting/Castle.Windsor.Extensions.Hosting.csproj
44+
dotnet restore ./src/Castle.Facilities.WcfIntegration/Castle.Facilities.WcfIntegration.csproj
45+
dotnet restore ./src/Castle.Facilities.WcfIntegration.Demo/Castle.Facilities.WcfIntegration.Demo.csproj
46+
dotnet restore ./src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests.csproj
47+
dotnet restore ./src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj
48+
49+
50+
GOTO build
51+
52+
:build
53+
dotnet build ./tools/Explicit.NuGet.Versions/Explicit.NuGet.Versions.sln
54+
dotnet build Castle.Windsor.sln -c %Configuration%
55+
GOTO test
56+
57+
:test
58+
59+
echo -------------
60+
echo Running Tests
61+
echo -------------
62+
63+
dotnet test src\Castle.Windsor.Tests || exit /b 1
64+
dotnet test src\Castle.Windsor.Extensions.DependencyInjection.Tests || exit /b 1
65+
dotnet test src\Castle.Facilities.AspNetCore.Tests || exit /b 1
66+
dotnet test src\Castle.Facilities.AspNet.SystemWeb.Tests || exit /b 1
67+
dotnet test src\Castle.Facilities.AspNet.Mvc.Tests || exit /b 1
68+
dotnet test src\Castle.Facilities.AspNet.WebApi.Tests || exit /b 1
69+
rem dotnet test src\Castle.Facilities.WcfIntegration.Tests || exit /b 1
70+
71+
GOTO nuget_explicit_versions
72+
73+
:nuget_explicit_versions
74+
75+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.windsor"
76+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.loggingfacility"
77+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.windsor.extensions.dependencyinjection"
78+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.windsor.extensions.hosting"
79+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.facilities.aspnetcore"
80+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.facilities.aspnet.mvc"
81+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.facilities.aspnet.webapi"
82+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.facilities.aspnet.systemweb"
83+
.\tools\Explicit.NuGet.Versions\build\nev.exe ".\build" "castle.wcfintegrationfacility"

src/Castle.Facilities.AspNet.Mvc.Tests/Castle.Facilities.AspNet.Mvc.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1919
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
2020
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
2121
<PackageReference Include="NUnit" Version="3.13.3" />
22-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
22+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

src/Castle.Facilities.AspNet.SystemWeb.Tests/Castle.Facilities.AspNet.SystemWeb.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
2323
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
2424
<PackageReference Include="NUnit" Version="3.13.3" />
25-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
25+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

src/Castle.Facilities.AspNet.WebApi.Tests/Castle.Facilities.AspNet.WebApi.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Microsoft.AspNet.WebApi" Version="5.2.3" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1919
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
2020
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
2121
<PackageReference Include="NUnit" Version="3.13.3" />
22-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
22+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

src/Castle.Facilities.AspNetCore.Tests/Castle.Facilities.AspNetCore.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ItemGroup>
88
<!-- This is an intentional upgrade to NUnit. This is the solution for https://github.com/castleproject/Windsor/issues/243 once we upgrade NUnit and make dotnet test a first class citizen-->
99
<PackageReference Include="NUnit" Version="3.13.3" />
10-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
10+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1212
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
1313
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.2" />
1414
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.0.2" />

src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1616
<PackageReference Include="NUnit" Version="3.13.3" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
1818
</ItemGroup>
1919

2020
<ItemGroup>

src/Castle.Windsor.Extensions.DependencyInjection.Tests/Castle.Windsor.Extensions.DependencyInjection.Tests.csproj

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77

@@ -11,11 +11,11 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1515
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
16-
<PackageReference Include="xunit" Version="2.4.1" />
17-
<PackageReference Include="xunit.assert" Version="2.4.1" />
18-
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
16+
<PackageReference Include="xunit" Version="2.4.2" />
17+
<PackageReference Include="xunit.assert" Version="2.4.2" />
18+
<PackageReference Include="xunit.extensibility.core" Version="2.4.2" />
1919
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
2020
</ItemGroup>
2121

@@ -29,6 +29,15 @@
2929
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="6.0.0" />
3030
</ItemGroup>
3131

32+
<ItemGroup Condition="'$(TargetFramework)'=='net8.0'">
33+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
34+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
35+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
36+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
37+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="8.0.0" />
38+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
39+
</ItemGroup>
40+
3241
<ItemGroup>
3342
<ProjectReference Include="..\Castle.Windsor.Extensions.DependencyInjection\Castle.Windsor.Extensions.DependencyInjection.csproj" />
3443
</ItemGroup>

0 commit comments

Comments
 (0)