Allow Slim to build NonPublic constructors

This commit is contained in:
2025-07-30 00:17:24 +02:00
parent e9947c6f74
commit 6c4edd3ef8
6 changed files with 34 additions and 39 deletions
+10 -9
View File
@@ -1,4 +1,4 @@
name: Slim CD Pipeline
name: Slim CD Pipeline
on:
push:
@@ -6,7 +6,6 @@ on:
- master
jobs:
build:
environment: Default
strategy:
@@ -21,30 +20,32 @@ jobs:
Test_Project_Path: Slim.Tests\Slim.Tests.csproj
Source_Project_Path: Slim\Slim.csproj
Integration_Project_Path: Slim.Integration\Slim.Integration.csproj
Actions_Allow_Unsecure_Commands: true
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'
- name: Restore dependencies
run: dotnet restore $env:Solution_Path
- name: Build Slim project
run: dotnet build Slim -c $env:Configuration
run: dotnet build Slim -c $env:Configuration --no-restore
- name: Build Slim.Integration project
run: dotnet build $env:Integration_Project_Path -c $env:Configuration
run: dotnet build $env:Integration_Project_Path -c $env:Configuration --no-restore
- name: Package Slim
run: dotnet pack -c Release -o . $env:Source_Project_Path
run: dotnet pack -c Release -o . $env:Source_Project_Path --no-build
- name: Package Slim.Integration
run: dotnet pack -c Release -o . $env:Integration_Project_Path
run: dotnet pack -c Release -o . $env:Integration_Project_Path --no-build
- name: Publish
run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
+11 -14
View File
@@ -1,4 +1,4 @@
name: Slim CI Pipeline
name: Slim CI Pipeline
on:
push:
@@ -9,9 +9,7 @@ on:
- master
jobs:
build:
strategy:
matrix:
targetplatform: [x64]
@@ -23,27 +21,26 @@ jobs:
Test_Project_Path: Slim.Tests\Slim.Tests.csproj
Integration_Test_Project_Path: Slim.Integration.Tests\Slim.Integration.Tests.csproj
Source_Project_Path: Slim\Slim.csproj
Actions_Allow_Unsecure_Commands: true
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.x'
- name: Restore dependencies
run: dotnet restore $env:Solution_Path
- name: Build solution
run: dotnet build $env:Solution_Path --no-restore --configuration Release
- name: Execute Slim Unit Tests
run: dotnet test $env:Test_Project_Path
run: dotnet test $env:Test_Project_Path --no-build --configuration Release --verbosity normal
- name: Execute Slim.Integration Unit Tests
run: dotnet test $env:Integration_Test_Project_Path
- name: Restore Project
run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier
env:
Configuration: Debug
RuntimeIdentifier: win-${{ matrix.targetplatform }}
run: dotnet test $env:Integration_Test_Project_Path --no-build --configuration Release --verbosity normal
+3 -6
View File
@@ -27,18 +27,15 @@ public class ServiceManagerTests
}
[TestMethod]
public void DependencyOnPrivateConstructorServiceThrows()
public void DependencyOnPrivateConstructorServiceImplements()
{
var di = new ServiceManager();
di.RegisterSingleton<IPrivateConstructorService, PrivateConstructorService>();
di.RegisterSingleton<IDependentOnPrivateCtrService, DependentOnPrivateCtrService>();
var action = new Action(() =>
{
di.GetService<IDependentOnPrivateCtrService>();
});
var service = di.GetService<IDependentOnPrivateCtrService>();
action.Should().Throw<DependencyInjectionException>();
service.Should().NotBeNull();
}
[TestMethod]
+6 -6
View File
@@ -2,16 +2,16 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.0.0-alpha0001" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
+1 -1
View File
@@ -807,7 +807,7 @@ public sealed class ServiceManager : IServiceManager
/*
* Order constructors to give priority to constructors that have PrefferedConstructorAttribute decorator
*/
var constructors = implementType.GetConstructors()
var constructors = implementType.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(c => c.GetCustomAttribute<DoNotInjectAttribute>() is null)
.OrderBy(c =>
c.GetCustomAttribute<PreferredConstructorAttribute>() is PreferredConstructorAttribute preferredConstructorAttribute ?
+3 -3
View File
@@ -8,10 +8,10 @@
<Company />
<Product></Product>
<Description>Service lifetime management and dependency injection framework.</Description>
<AssemblyVersion>1.10.1</AssemblyVersion>
<FileVersion>1.10.1</FileVersion>
<AssemblyVersion>1.10.2</AssemblyVersion>
<FileVersion>1.10.2</FileVersion>
<PackageProjectUrl>https://github.com/AlexMacocian/Slim</PackageProjectUrl>
<Version>1.10.1</Version>
<Version>1.10.2</Version>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>