Skip to content

Commit f2f220c

Browse files
committed
Squashed commit of the following:
commit 99ff4e4 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Nov 19 14:23:23 2023 +0100 Update README.md commit 32adc57 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Nov 19 14:15:41 2023 +0100 More keyed tests commit 3a442d0 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Nov 19 01:22:28 2023 +0100 Update linux-macOS-CI.yml commit 7ac91cb Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Sun Nov 19 01:17:19 2023 +0100 Add .NET 8 target commit 13af843 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Wed Sep 27 00:06:24 2023 +0200 Update appveyor.yml commit a37806c Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Wed Sep 27 00:00:27 2023 +0200 Use latest preview Stashbox / MS.DI commit b3f1f10 Author: Peter Csajtai <peter.csajtai@outlook.com> Date: Tue Sep 5 17:56:01 2023 +0200 Support for .NET 8 keyed registrations
1 parent 8f6a69f commit f2f220c

20 files changed

+309
-252
lines changed

.github/workflows/linux-macOS-CI.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Build on Linux and macOS
22
on:
33
push:
4-
branches: [ master ]
4+
branches:
5+
- '*'
56
paths-ignore:
67
- '**.md'
78
- 'appveyor*'
@@ -28,6 +29,7 @@ jobs:
2829
5.0.x
2930
6.0.x
3031
7.0.x
32+
8.0.x
3133
- name: Restore
3234
run: dotnet restore
3335
- name: Test
@@ -36,13 +38,17 @@ jobs:
3638
dotnet test test/stashbox.extensions.dependencyinjection.specificationtests/stashbox.extensions.dependencyinjection.specificationtests.csproj -c Release -f net5.0 --no-restore
3739
dotnet test test/stashbox.extensions.dependencyinjection.specificationtests/stashbox.extensions.dependencyinjection.specificationtests.csproj -c Release -f net6.0 --no-restore
3840
dotnet test test/stashbox.extensions.dependencyinjection.specificationtests/stashbox.extensions.dependencyinjection.specificationtests.csproj -c Release -f net7.0 --no-restore
41+
dotnet test test/stashbox.extensions.dependencyinjection.specificationtests/stashbox.extensions.dependencyinjection.specificationtests.csproj -c Release -f net8.0 --no-restore
3942
dotnet test test/stashbox.extensions.dependencyinjection.tests/stashbox.extensions.dependencyinjection.tests.csproj -c Release -f netcoreapp3.1 --no-restore
4043
dotnet test test/stashbox.extensions.dependencyinjection.tests/stashbox.extensions.dependencyinjection.tests.csproj -c Release -f net5.0 --no-restore
4144
dotnet test test/stashbox.extensions.dependencyinjection.tests/stashbox.extensions.dependencyinjection.tests.csproj -c Release -f net6.0 --no-restore
4245
dotnet test test/stashbox.extensions.dependencyinjection.tests/stashbox.extensions.dependencyinjection.tests.csproj -c Release -f net7.0 --no-restore
46+
dotnet test test/stashbox.extensions.dependencyinjection.tests/stashbox.extensions.dependencyinjection.tests.csproj -c Release -f net8.0 --no-restore
4347
dotnet test test/stashbox.aspnetcore.multitenant.tests/stashbox.aspnetcore.multitenant.tests.csproj -c Release -f netcoreapp3.1 --no-restore
4448
dotnet test test/stashbox.aspnetcore.multitenant.tests/stashbox.aspnetcore.multitenant.tests.csproj -c Release -f net5.0 --no-restore
4549
dotnet test test/stashbox.aspnetcore.multitenant.tests/stashbox.aspnetcore.multitenant.tests.csproj -c Release -f net6.0 --no-restore
4650
dotnet test test/stashbox.aspnetcore.multitenant.tests/stashbox.aspnetcore.multitenant.tests.csproj -c Release -f net7.0 --no-restore
51+
dotnet test test/stashbox.aspnetcore.multitenant.tests/stashbox.aspnetcore.multitenant.tests.csproj -c Release -f net8.0 --no-restore
4752
dotnet test test/stashbox.aspnetcore.testing.tests/stashbox.aspnetcore.testing.tests.csproj -c Release -f net6.0 --no-restore
48-
dotnet test test/stashbox.aspnetcore.testing.tests/stashbox.aspnetcore.testing.tests.csproj -c Release -f net7.0 --no-restore
53+
dotnet test test/stashbox.aspnetcore.testing.tests/stashbox.aspnetcore.testing.tests.csproj -c Release -f net7.0 --no-restore
54+
dotnet test test/stashbox.aspnetcore.testing.tests/stashbox.aspnetcore.testing.tests.csproj -c Release -f net8.0 --no-restore

README.md

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@ This repository contains [Stashbox](https://github.com/z4kn4fein/stashbox) integ
2020

2121
### Table of Contents
2222
* [ASP.NET Core](#aspnet-core)
23-
- [ASP.NET Core 5](#aspnet-core-5)
24-
- [ASP.NET Core 6](#aspnet-core-6)
2523
+ [Controller / View activation](#controller--view-activation)
26-
- [ASP.NET Core 5](#aspnet-core-5-1)
27-
- [ASP.NET Core 6](#aspnet-core-6-1)
2824
+ [Multitenant](#multitenant)
29-
- [ASP.NET Core 5](#aspnet-core-5-2)
30-
- [ASP.NET Core 6](#aspnet-core-6-2)
3125
+ [Testing](#testing)
3226
* [.NET Generic Host](#net-generic-host)
3327
* [ServiceCollection Based Applications](#servicecollection-based-applications)
@@ -36,58 +30,7 @@ This repository contains [Stashbox](https://github.com/z4kn4fein/stashbox) integ
3630

3731
## ASP.NET Core
3832
The following example shows how you can integrate Stashbox (with the `Stashbox.Extensions.Hosting` package) as the default `IServiceProvider` implementation into your ASP.NET Core application:
39-
#### ASP.NET Core 5
40-
```c#
41-
public class Program
42-
{
43-
public static void Main(string[] args)
44-
{
45-
CreateHostBuilder(args).Build().Run();
46-
}
47-
48-
public static IHostBuilder CreateHostBuilder(String[] args)
49-
{
50-
return Host.CreateDefaultBuilder(args)
51-
.UseStashbox(container => // Optional configuration options.
52-
{
53-
container.Configure(options => { /*...*/ });
54-
})
55-
.ConfigureContainer<IStashboxContainer>((context, container) =>
56-
{
57-
// Execute container validation in development mode.
58-
if (context.HostingEnvironment.IsDevelopment())
59-
container.Validate();
60-
})
61-
.ConfigureWebHostDefaults(
62-
webBuilder => webBuilder
63-
.UseStartup<Startup>());
64-
}
65-
}
66-
```
6733

68-
You can also use the `ConfigureContainer()` method in your `Startup` class to use further configuration options:
69-
```c#
70-
public class Startup
71-
{
72-
public void ConfigureServices(IServiceCollection services)
73-
{
74-
// Service configuration.
75-
}
76-
77-
public void ConfigureContainer(IStashboxContainer container)
78-
{
79-
// Container configuration.
80-
container.Configure(config => config.WithLifetimeValidation());
81-
}
82-
83-
public void Configure(IApplicationBuilder app)
84-
{
85-
// Application configuration.
86-
}
87-
}
88-
```
89-
90-
#### ASP.NET Core 6
9134
```c#
9235
var builder = WebApplication.CreateBuilder(args);
9336

@@ -109,21 +52,6 @@ builder.Host.ConfigureContainer<IStashboxContainer>((context, container) =>
10952
By default the ASP.NET Core framework uses the `DefaultControllerActivator` to instantiate controllers, but it uses the `ServiceProvider` only for instantiating their constructor dependencies. This behaviour could hide important errors Stashbox would throw in case of a misconfiguration, so it's recommended to let Stashbox activate your controllers and views.
11053

11154
You can enable this by adding the following options to your service configuration:
112-
#### ASP.NET Core 5
113-
```c#
114-
public void ConfigureServices(IServiceCollection services)
115-
{
116-
// For controllers only.
117-
services.AddControllers()
118-
.AddControllersAsServices();
119-
120-
// For controllers and views.
121-
services.AddControllersWithViews()
122-
.AddControllersAsServices()
123-
.AddViewComponentsAsServices();
124-
}
125-
```
126-
#### ASP.NET Core 6
12755

12856
```c#
12957
// For controllers only.
@@ -158,42 +86,7 @@ public class HttpHeaderTenantIdExtractor : ITenantIdExtractor
15886
}
15987
}
16088
```
161-
#### ASP.NET Core 5
162-
```c#
163-
public static IHostBuilder CreateHostBuilder(String[] args)
164-
{
165-
return Host.CreateDefaultBuilder(args)
166-
.UseStashboxMultitenant<HttpHeaderTenantIdExtractor>(
167-
options => // Multi-tenant configuration options.
168-
{
169-
// The default service registration, it registers into the root container.
170-
// It also could be registered into the default
171-
// service collection with the ConfigureServices() API.
172-
options.RootContainer.Register<IDependency, DefaultDependency>();
173-
174-
// Configure tenants.
175-
options.ConfigureTenant("TenantA", tenant =>
176-
// Register tenant specific service override
177-
tenant.Register<IDependency, TenantASpecificDependency>());
178-
179-
options.ConfigureTenant("TenantB", tenant =>
180-
// Register tenant specific service override
181-
tenant.Register<IDependency, TenantBSpecificDependency>());
182-
})
183-
// The container parameter is the tenant distributor itself.
184-
// Calling its Validate() method will verify the root container and each tenant.
185-
.ConfigureContainer<IStashboxContainer>((context, container) =>
186-
{
187-
// Validate the root container and all tenants.
188-
if (context.HostingEnvironment.IsDevelopment())
189-
container.Validate();
190-
})
191-
.ConfigureWebHostDefaults(
192-
webBuilder => webBuilder
193-
.UseStartup<Startup>());
194-
}
195-
```
196-
#### ASP.NET Core 6
89+
19790
```c#
19891
var builder = WebApplication.CreateBuilder(args);
19992
builder.Host.UseStashboxMultitenant<HttpHeaderTenantIdExtractor>(

appveyor.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
environment:
2-
build_version: 5.3.0
2+
build_version: 5.4.0
33

44
version: $(build_version)-{build}
55

@@ -16,7 +16,12 @@ skip_commits:
1616
- '**/*.md'
1717

1818
install:
19-
- dotnet tool install -g InheritDocTool
19+
- ps: |
20+
dotnet tool install -g InheritDocTool
21+
22+
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
23+
./dotnet-install.ps1 -Channel 7.0
24+
./dotnet-install.ps1 -Channel 8.0
2025
2126
dotnet_csproj:
2227
patch: true
@@ -42,13 +47,19 @@ after_build:
4247
test_script:
4348
- dotnet test test\stashbox.extensions.dependencyinjection.specificationtests\stashbox.extensions.dependencyinjection.specificationtests.csproj -f netcoreapp3.1 -c %CONFIGURATION% --no-build
4449
- dotnet test test\stashbox.extensions.dependencyinjection.specificationtests\stashbox.extensions.dependencyinjection.specificationtests.csproj -f net6.0 -c %CONFIGURATION% --no-build
50+
- dotnet test test\stashbox.extensions.dependencyinjection.specificationtests\stashbox.extensions.dependencyinjection.specificationtests.csproj -f net7.0 -c %CONFIGURATION% --no-build
51+
- dotnet test test\stashbox.extensions.dependencyinjection.specificationtests\stashbox.extensions.dependencyinjection.specificationtests.csproj -f net8.0 -c %CONFIGURATION% --no-build
4552
- dotnet test test\stashbox.extensions.dependencyinjection.tests\stashbox.extensions.dependencyinjection.tests.csproj -f netcoreapp3.1 -c %CONFIGURATION% --no-build
4653
- dotnet test test\stashbox.extensions.dependencyinjection.tests\stashbox.extensions.dependencyinjection.tests.csproj -f net6.0 -c %CONFIGURATION% --no-build
54+
- dotnet test test\stashbox.extensions.dependencyinjection.tests\stashbox.extensions.dependencyinjection.tests.csproj -f net7.0 -c %CONFIGURATION% --no-build
55+
- dotnet test test\stashbox.extensions.dependencyinjection.tests\stashbox.extensions.dependencyinjection.tests.csproj -f net8.0 -c %CONFIGURATION% --no-build
4756
- dotnet test test\stashbox.aspnetcore.multitenant.tests\stashbox.aspnetcore.multitenant.tests.csproj -f netcoreapp3.1 -c %CONFIGURATION% --no-build
4857
- dotnet test test\stashbox.aspnetcore.multitenant.tests\stashbox.aspnetcore.multitenant.tests.csproj -f net6.0 -c %CONFIGURATION% --no-build
4958
- dotnet test test\stashbox.aspnetcore.multitenant.tests\stashbox.aspnetcore.multitenant.tests.csproj -f net7.0 -c %CONFIGURATION% --no-build
59+
- dotnet test test\stashbox.aspnetcore.multitenant.tests\stashbox.aspnetcore.multitenant.tests.csproj -f net8.0 -c %CONFIGURATION% --no-build
5060
- dotnet test test\stashbox.aspnetcore.testing.tests\stashbox.aspnetcore.testing.tests.csproj -f net6.0 -c %CONFIGURATION% --no-build
5161
- dotnet test test\stashbox.aspnetcore.testing.tests\stashbox.aspnetcore.testing.tests.csproj -f net7.0 -c %CONFIGURATION% --no-build
62+
- dotnet test test\stashbox.aspnetcore.testing.tests\stashbox.aspnetcore.testing.tests.csproj -f net8.0 -c %CONFIGURATION% --no-build
5263

5364
artifacts:
5465
- path: artifacts\Stashbox.*.nupkg

src/stashbox.aspnetcore.hosting/stashbox.aspnetcore.hosting.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<ItemGroup>
3535
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
36-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
36+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
3737
</ItemGroup>
3838

3939
<ItemGroup>

src/stashbox.aspnetcore.multitenant/stashbox.aspnetcore.multitenant.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<AssemblyTitle>Stashbox AspNetCore Multitenant</AssemblyTitle>
77
<Authors>Peter Csajtai</Authors>
88
<Company>Peter Csajtai</Company>
9-
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
9+
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111
<AssemblyName>Stashbox.AspNetCore.Multitenant</AssemblyName>
1212
<AssemblyOriginatorKeyFile>../../sn.snk</AssemblyOriginatorKeyFile>
@@ -34,7 +34,7 @@
3434

3535
<ItemGroup>
3636
<FrameworkReference Include="Microsoft.AspNetCore.App" />
37-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
37+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
3838
</ItemGroup>
3939

4040
<ItemGroup>

src/stashbox.aspnetcore.testing/stashbox.aspnetcore.testing.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Stashbox extension for writing integration tests for MVC applications.</Description>
5-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
5+
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
66
<AssemblyName>Stashbox.AspNetCore.Testing</AssemblyName>
77
<RootNamespace>Stashbox.AspNetCore.Testing</RootNamespace>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -40,8 +40,12 @@
4040
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.2" />
4141
</ItemGroup>
4242

43+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
44+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
45+
</ItemGroup>
46+
4347
<ItemGroup>
44-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
48+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
4549
</ItemGroup>
4650

4751
<ItemGroup>

src/stashbox.extensions.dependencyinjection/ServiceCollectionExtensions.Assembly.cs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ public static IServiceCollection ScanAssemblyOf<TService>(this IServiceCollectio
2828
Action<RegistrationConfigurator>? configurator = null)
2929
where TService : class
3030
{
31-
services.Add(new ServiceDescriptor(typeof(StashboxServiceDescriptor),
32-
new StashboxServiceDescriptor(container => container.RegisterAssemblyContaining< TService>(selector,
33-
serviceTypeSelector,
34-
registerSelf,
35-
configurator))));
31+
services.Add(new StashboxServiceDescriptor(container => container.RegisterAssemblyContaining<TService>(selector,
32+
serviceTypeSelector,
33+
registerSelf,
34+
configurator)));
3635
return services;
3736
}
3837

@@ -46,19 +45,18 @@ public static IServiceCollection ScanAssemblyOf<TService>(this IServiceCollectio
4645
/// <param name="registerSelf">If it's true the types will be registered to their own type too.</param>
4746
/// <param name="configurator">Configurator action for the registered types.</param>
4847
/// <returns>The service collection.</returns>
49-
public static IServiceCollection ScanAssemblyOf(this IServiceCollection services,
48+
public static IServiceCollection ScanAssemblyOf(this IServiceCollection services,
5049
Type type,
5150
Func<Type, bool>? selector = null,
5251
Func<Type, Type, bool>? serviceTypeSelector = null,
5352
bool registerSelf = true,
5453
Action<RegistrationConfigurator>? configurator = null)
5554
{
56-
services.Add(new ServiceDescriptor(typeof(StashboxServiceDescriptor),
57-
new StashboxServiceDescriptor(container => container.RegisterAssemblyContaining(type,
58-
selector,
59-
serviceTypeSelector,
60-
registerSelf,
61-
configurator))));
55+
services.Add(new StashboxServiceDescriptor(container => container.RegisterAssemblyContaining(type,
56+
selector,
57+
serviceTypeSelector,
58+
registerSelf,
59+
configurator)));
6260
return services;
6361
}
6462

@@ -79,12 +77,11 @@ public static IServiceCollection ScanAssembly(this IServiceCollection services,
7977
bool registerSelf = true,
8078
Action<RegistrationConfigurator>? configurator = null)
8179
{
82-
services.Add(new ServiceDescriptor(typeof(StashboxServiceDescriptor),
83-
new StashboxServiceDescriptor(container => container.RegisterAssembly(assembly,
84-
selector,
85-
serviceTypeSelector,
86-
registerSelf,
87-
configurator))));
80+
services.Add(new StashboxServiceDescriptor(container => container.RegisterAssembly(assembly,
81+
selector,
82+
serviceTypeSelector,
83+
registerSelf,
84+
configurator)));
8885
return services;
8986
}
9087

@@ -96,8 +93,7 @@ public static IServiceCollection ScanAssembly(this IServiceCollection services,
9693
/// <returns>The service collection.</returns>
9794
public static IServiceCollection ComposeAssembly(this IServiceCollection services, Assembly assembly)
9895
{
99-
services.Add(new ServiceDescriptor(typeof(StashboxServiceDescriptor),
100-
new StashboxServiceDescriptor(container => container.ComposeAssembly(assembly))));
96+
services.Add(new StashboxServiceDescriptor(container => container.ComposeAssembly(assembly)));
10197
return services;
10298
}
10399

@@ -108,11 +104,12 @@ public static IServiceCollection ComposeAssembly(this IServiceCollection service
108104
/// <param name="services">The service collection.</param>
109105
/// <param name="compositionRootArguments">Optional composition root constructor argument overrides.</param>
110106
/// <returns>The service collection.</returns>
111-
public static IServiceCollection ComposeBy<TCompositionRoot>(this IServiceCollection services, params object[] compositionRootArguments)
107+
public static IServiceCollection ComposeBy<TCompositionRoot>(this IServiceCollection services,
108+
params object[] compositionRootArguments)
112109
where TCompositionRoot : class, ICompositionRoot
113110
{
114-
services.Add(new ServiceDescriptor(typeof(StashboxServiceDescriptor),
115-
new StashboxServiceDescriptor(container => container.ComposeBy<TCompositionRoot>(compositionRootArguments))));
111+
services.Add(new StashboxServiceDescriptor(container =>
112+
container.ComposeBy<TCompositionRoot>(compositionRootArguments)));
116113
return services;
117114
}
118115

@@ -123,10 +120,11 @@ public static IServiceCollection ComposeBy<TCompositionRoot>(this IServiceCollec
123120
/// <param name="compositionRootType">The type of an <see cref="ICompositionRoot"/> implementation.</param>
124121
/// <param name="compositionRootArguments">Optional composition root constructor argument overrides.</param>
125122
/// <returns>The service collection.</returns>
126-
public static IServiceCollection ComposeBy(this IServiceCollection services, Type compositionRootType, params object[] compositionRootArguments)
123+
public static IServiceCollection ComposeBy(this IServiceCollection services, Type compositionRootType,
124+
params object[] compositionRootArguments)
127125
{
128-
services.Add(new ServiceDescriptor(typeof(StashboxServiceDescriptor),
129-
new StashboxServiceDescriptor(container => container.ComposeBy(compositionRootType, compositionRootArguments))));
126+
services.Add(new StashboxServiceDescriptor(container =>
127+
container.ComposeBy(compositionRootType, compositionRootArguments)));
130128
return services;
131129
}
132130
}

0 commit comments

Comments
 (0)