Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8093f98
Merge: 194ae36 4db2c40
Author: Peter Csajtai <[email protected]>
Date:   Sun Nov 19 00:14:51 2023 +0100

    Merge branch 'master' into dev

commit 194ae36
Author: Peter Csajtai <[email protected]>
Date:   Sun Nov 19 00:14:17 2023 +0100

    Update docs & changelog

commit 625a207
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 20:02:22 2023 +0100

    Update appveyor-release.yml

commit 754ade0
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 19:37:26 2023 +0100

    Update appveyor.yml

commit b73d9df
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 19:29:51 2023 +0100

    Update appveyor.yml

commit 8f99867
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 19:20:47 2023 +0100

    Update appveyor.yml

commit 9baa102
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 19:07:25 2023 +0100

    Update appveyor.yml

commit ce04688
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 19:01:47 2023 +0100

    Update appveyor.yml

commit 0f71ac0
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 18:52:49 2023 +0100

    Fix CI scripts

commit 3c011c5
Author: Peter Csajtai <[email protected]>
Date:   Sat Nov 18 18:34:11 2023 +0100

    Add .NET 8 target

commit ddf28c2
Author: Peter Csajtai <[email protected]>
Date:   Tue Sep 26 23:48:58 2023 +0200

    Prepare for MS keyed services support

commit 46422ea
Author: Peter Csajtai <[email protected]>
Date:   Sat Sep 16 19:21:08 2023 +0200

    Auto inject required members

commit 9ed831b
Author: Peter Csajtai <[email protected]>
Date:   Fri Sep 15 21:06:32 2023 +0200

    Update .version

commit 923b6d6
Author: Peter Csajtai <[email protected]>
Date:   Fri Sep 15 21:05:19 2023 +0200

    Add auto lifetime
  • Loading branch information
z4kn4fein committed Nov 18, 2023
1 parent 4db2c40 commit 43400bc
Show file tree
Hide file tree
Showing 52 changed files with 1,119 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/linux-macOS-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Restore
run: dotnet restore
- name: Test
run: |
dotnet test test/stashbox.tests.csproj -c Release -f netcoreapp3.1 --no-restore
dotnet test test/stashbox.tests.csproj -c Release -f net5.0 --no-restore
dotnet test test/stashbox.tests.csproj -c Release -f net6.0 --no-restore
dotnet test test/stashbox.tests.csproj -c Release -f net7.0 --no-restore
dotnet test test/stashbox.tests.csproj -c Release -f net7.0 --no-restore
dotnet test test/stashbox.tests.csproj -c Release -f net8.0 --no-restore
4 changes: 4 additions & 0 deletions .github/workflows/sonar-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
8.0.x
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.12.2
5.13.0
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v5.13.0] - 2023-11-18
### Added
- .NET 8.0 target.
- [#134](https://github.com/z4kn4fein/stashbox/issues/134) Concept of [Auto lifetime](https://z4kn4fein.github.io/stashbox/docs/guides/lifetimes#auto-lifetime):
- It aligns to the lifetime of the resolved service's dependencies. When the underlying service has a dependency with a higher lifespan, this lifetime will inherit that lifespan up to a given boundary.
- Auto injection of `required` members.
- MS.DI compatibility features for supporting [keyed services](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8#keyed-di-services):
- `DependencyName` attribute. When a parameter is marked with this attribute, the container will pass the given dependency's name to it.
- `WithUniversalName()` container configuration method. It sets the universal name which is a special name that allows named resolution work for any given name.
- `WithAdditionalDependencyNameAttribute()` container configuration method. It adds an attribute type that is considered a dependency name indicator just like the [`DependencyName` attribute](https://z4kn4fein.github.io/stashbox/docs/guides/service-resolution#attributes).
- `WithAdditionalDependencyAttribute()` container configuration method. It adds an attribute type that is considered a dependency indicator just like the [`Dependency` attribute](https://z4kn4fein.github.io/stashbox/docs/guides/service-resolution#attributes).

## [v5.12.2] - 2023-09-05
### Fixed
- There was an issue where using decorators with instance registrations resulted in resolution failure.
Expand Down Expand Up @@ -398,6 +410,7 @@ The validation was executed only at the expression tree building phase, so an al
- Removed the legacy container extension functionality.
- Removed the support of PCL v259.

[v5.13.0]: https://github.com/z4kn4fein/stashbox/compare/5.12.2...5.13.0
[v5.12.2]: https://github.com/z4kn4fein/stashbox/compare/5.12.1...5.12.2
[v5.12.1]: https://github.com/z4kn4fein/stashbox/compare/5.11.1...5.12.1
[v5.11.1]: https://github.com/z4kn4fein/stashbox/compare/5.11.0...5.11.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Stashbox is a lightweight, fast, and portable dependency injection framework for

Github (stable) | NuGet (stable) | Fuget (stable) | NuGet (pre-release)
--- | --- |---------------------------------------------------------------------------------------------------------------------------------| ---
[![Github release](https://img.shields.io/github/release/z4kn4fein/stashbox.svg)](https://github.com/z4kn4fein/stashbox/releases) | [![NuGet Version](https://buildstats.info/nuget/Stashbox)](https://www.nuget.org/packages/Stashbox/) | [![Stashbox on fuget.org](https://www.fuget.org/packages/Stashbox/badge.svg?v=5.12.2)](https://www.fuget.org/packages/Stashbox) | [![Nuget pre-release](https://img.shields.io/nuget/vpre/Stashbox)](https://www.nuget.org/packages/Stashbox/)
[![Github release](https://img.shields.io/github/release/z4kn4fein/stashbox.svg)](https://github.com/z4kn4fein/stashbox/releases) | [![NuGet Version](https://buildstats.info/nuget/Stashbox)](https://www.nuget.org/packages/Stashbox/) | [![Stashbox on fuget.org](https://www.fuget.org/packages/Stashbox/badge.svg?v=5.13.0)](https://www.fuget.org/packages/Stashbox) | [![Nuget pre-release](https://img.shields.io/nuget/vpre/Stashbox)](https://www.nuget.org/packages/Stashbox/)

## Core Attributes
- 🚀 Fast, thread-safe, and lock-free operations.
Expand Down
4 changes: 4 additions & 0 deletions appveyor-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ install:
$env:build_version = Get-Content ".version"
Update-AppveyorBuild -Version "$env:build_version-$env:appveyor_build_number"
dotnet tool install -g InheritDocTool
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
./dotnet-install.ps1 -Channel 7.0
./dotnet-install.ps1 -Channel 8.0
dotnet_csproj:
patch: true
Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ install:
$env:build_version = Get-Content ".version"
Update-AppveyorBuild -Version "$env:build_version-preview-$env:appveyor_build_number"
dotnet tool install -g InheritDocTool
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
./dotnet-install.ps1 -Channel 7.0
./dotnet-install.ps1 -Channel 8.0
dotnet_csproj:
patch: true
Expand All @@ -46,6 +50,7 @@ test_script:
- dotnet test test\stashbox.tests.csproj -f net5.0 -c %configuration% --no-build
- dotnet test test\stashbox.tests.csproj -f net6.0 -c %configuration% --no-build
- dotnet test test\stashbox.tests.csproj -f net7.0 -c %configuration% --no-build
- dotnet test test\stashbox.tests.csproj -f net8.0 -c %configuration% --no-build

artifacts:
- path: artifacts\Stashbox.*.nupkg
Expand Down
73 changes: 71 additions & 2 deletions docs/docs/configuration/container-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ new StashboxContainer(options => options

## Auto member-injection
With this option, you can enable or disable the auto member-injection without [attributes](/docs/guides/service-resolution#attributes).

<CodeDescPanel>
<div>

Expand Down Expand Up @@ -140,9 +141,26 @@ new StashboxContainer(options => options
</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

:::note
Member selection filter: `config.WithAutoMemberInjection(filter: member => member.Type != typeof(IJob))`
#### Member selection filter
You can pass your own member selection logic to control which members should be auto injected.

</div>
<div>

```cs
new StashboxContainer(options => options
.WithAutoMemberInjection(
filter: member => member.Type != typeof(ILogger)));
```

</div>
</CodeDescPanel>

:::info
Members defined with C# 11's [`required`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required) keyword are automatically injected by the container.
:::

## Constructor selection
Expand Down Expand Up @@ -328,6 +346,57 @@ new StashboxContainer(options => options
</div>
</CodeDescPanel>

## Named service resolution
<CodeDescPanel>
<div>

### `WithUniversalName`
Sets the universal name that represents a special name which allows named resolution work for any given name.

</div>
<div>

```cs
new StashboxContainer(options => options
.WithUniversalName("Any"));
```

</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

### `WithAdditionalDependencyNameAttribute`
Adds an attribute type that is considered a dependency name indicator just like the [`DependencyName` attribute](/docs/guides/service-resolution#attributes).

</div>
<div>

```cs
new StashboxContainer(options => options
.WithAdditionalDependencyNameAttribute<CustomNameAttribute>());
```

</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

### `WithAdditionalDependencyAttribute`
Adds an attribute type that is considered a dependency indicator just like the [`Dependency` attribute](/docs/guides/service-resolution#attributes).

</div>
<div>

```cs
new StashboxContainer(options => options
.WithAdditionalDependencyAttribute<CustomDependencyAttribute>());
```

</div>
</CodeDescPanel>

## Default value injection
<CodeDescPanel>
Expand Down
40 changes: 38 additions & 2 deletions docs/docs/configuration/registration-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ container.Register<ILogger, ConsoleLogger>(config => config
<div>

### `WithPerScopedRequestLifetime`
Sets the lifetime to `PerScopedRequestLifetime`. That means this registration will behave like a singleton within every scoped resolution request.
Sets the lifetime to `PerScopedRequestLifetime`. This lifetime will create a new instance between scoped services. This means that every scoped service will get a different instance but within their dependency tree it will behave as a singleton.

</div>
<div>
Expand All @@ -390,6 +390,40 @@ container.Register<ILogger, ConsoleLogger>(options => options
<CodeDescPanel>
<div>

### `WithPerRequestLifetime`
Sets the lifetime to `PerRequestLifetime`. This lifetime will create a new instance between resolution requests. Within the request the same instance will be re-used.

</div>
<div>

```cs
container.Register<ILogger, ConsoleLogger>(options => options
.WithPerRequestLifetime());
```

</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

### `WithAutoLifetime`
Sets the lifetime to auto lifetime. This lifetime aligns to the lifetime of the resolved service's dependencies. When the underlying service has a dependency with a higher lifespan, this lifetime will inherit that lifespan up to a given boundary.

</div>
<div>

```cs
container.Register<ILogger, ConsoleLogger>(options => options
.WithAutoLifetime(Lifetimes.Scoped /* boundary lifetime */));
```

</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

### `WithLifetime`
Sets a custom lifetime for the registration.

Expand Down Expand Up @@ -708,7 +742,9 @@ container.Register<ILogger, ConsoleLogger>(options => options
</div>
</CodeDescPanel>


:::info
Members defined with C# 11's [`required`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/required) keyword are automatically injected by the container.
:::

## Injection parameters
<CodeDescPanel>
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/getting-started/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ Stashbox and its extensions are distributed via [NuGet](https://www.nuget.org/pa

You can install the package by typing the following into the Package Manager Console:
```powershell
Install-Package Stashbox -Version 5.12.2
Install-Package Stashbox -Version 5.13.0
```

</TabItem>
<TabItem value="dotnet CLI" label="dotnet CLI">

You can install the package by using the dotnet cli:
```bash
dotnet add package Stashbox --version 5.12.2
dotnet add package Stashbox --version 5.13.0
```

</TabItem>
<TabItem value="PackageReference" label="PackageReference">

You can add the package into the package references of your `.csproj`:
```xml
<PackageReference Include="Stashbox" Version="5.12.2" />
<PackageReference Include="Stashbox" Version="5.13.0" />
```

</TabItem>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/getting-started/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ These are the latest available stable and pre-release versions:

Github (stable) | NuGet (stable) | Fuget (stable) | NuGet (daily)
--- | --- |---------------------------------------------------------------------------------------------------------------------------------| ---
[![Github release](https://img.shields.io/github/release/z4kn4fein/stashbox.svg)](https://github.com/z4kn4fein/stashbox/releases) | [![NuGet Version](https://buildstats.info/nuget/Stashbox)](https://www.nuget.org/packages/Stashbox/) | [![Stashbox on fuget.org](https://www.fuget.org/packages/Stashbox/badge.svg?v=5.12.2)](https://www.fuget.org/packages/Stashbox) | [![Nuget pre-release](https://img.shields.io/nuget/vpre/Stashbox)](https://www.nuget.org/packages/Stashbox/)
[![Github release](https://img.shields.io/github/release/z4kn4fein/stashbox.svg)](https://github.com/z4kn4fein/stashbox/releases) | [![NuGet Version](https://buildstats.info/nuget/Stashbox)](https://www.nuget.org/packages/Stashbox/) | [![Stashbox on fuget.org](https://www.fuget.org/packages/Stashbox/badge.svg?v=5.13.0)](https://www.fuget.org/packages/Stashbox) | [![Nuget pre-release](https://img.shields.io/nuget/vpre/Stashbox)](https://www.nuget.org/packages/Stashbox/)

## Core attributes
- 🚀 Fast, thread-safe, and lock-free operations.
Expand Down
68 changes: 64 additions & 4 deletions docs/docs/guides/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ It is the same as scoped lifetime, except the given service will be selected onl

You can also let a service [define](/docs/guides/scopes#service-as-scope) its own named scope. During registration, this scope can be referred to by its name upon using a named scope lifetime.

:::note
Services with named scope lifetime are disposed when the related named scope is being disposed.
:::

</div>
<div>

Expand Down Expand Up @@ -213,6 +209,10 @@ DbJobExecutor executor = scope.Resolve<DbJobExecutor>();
</div>
</CodeDescPanel>

:::note
Services with named scope lifetime are disposed when the related named scope is being disposed.
:::

## Per-request lifetime

<CodeDescPanel>
Expand Down Expand Up @@ -249,6 +249,66 @@ container.Register<IJob, DbBackup>(options => options
</div>
</CodeDescPanel>

## Auto lifetime

<CodeDescPanel>
<div>

The requested service's lifetime will align to the lifetime of its dependencies. When the requested service has a dependency with a higher lifespan, this lifetime will inherit that lifespan up to a given boundary.

</div>
<div>

```cs
container.Register<IJob, DbBackup>(options => options
.WithAutoLifetime(Lifetimes.Scoped /* boundary lifetime */));
```

</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

If the requested service has auto lifetime with a scoped boundary and it has only transient dependencies, it'll inherit their transient lifetime.

</div>
<div>

```cs
container.Register<ILogger, Logger>();

container.Register<IJob, DbBackup>(options => options
.WithAutoLifetime(Lifetimes.Scoped /* boundary lifetime */));

// job has transient lifetime.
var job = container.Resolve<IJob>();
```

</div>
</CodeDescPanel>

<CodeDescPanel>
<div>

When there's a dependency with higher lifespan than the given boundary, the requested service will get the boundary lifetime.

</div>
<div>

```cs
container.RegisterSingleton<ILogger, Logger>();

container.Register<IJob, DbBackup>(options => options
.WithAutoLifetime(Lifetimes.Scoped /* boundary lifetime */));

// job has scoped lifetime.
var job = container.Resolve<IJob>();
```

</div>
</CodeDescPanel>

## Custom lifetime
If you'd like to use a custom lifetime, you can create your implementation by inheriting either from `FactoryLifetimeDescriptor` or from `ExpressionLifetimeDescriptor`, depending on how do you want to manage the service instances.

Expand Down
Loading

0 comments on commit 43400bc

Please sign in to comment.