Skip to content

Commit

Permalink
Fix an issue with decorating instance registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Sep 5, 2023
1 parent 139c9e1 commit c415008
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.12.1
5.12.2
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.12.2] - 2023-09-05
### Fixed
- There was an issue where using decorators with instance registrations resulted in resolution failure.

## [v5.12.1] - 2023-09-05
### Fixed
- [#144](https://github.com/z4kn4fein/stashbox/issues/144): There was a case where closed generic decorators were not taken into account during service resolution.
Expand Down Expand Up @@ -394,6 +398,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.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
[v5.11.0]: https://github.com/z4kn4fein/stashbox/compare/5.10.2...5.11.0
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.1)](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.12.2)](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
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.1
Install-Package Stashbox -Version 5.12.2
```

</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.1
dotnet add package Stashbox --version 5.12.2
```

</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.1" />
<PackageReference Include="Stashbox" Version="5.12.2" />
```

</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.1)](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.12.2)](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
2 changes: 1 addition & 1 deletion docs/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function HomepageHeader() {

<div className={styles.installContainer}>
<div className={styles.install}>
<pre><span className={styles.command_start}>{'$'} </span><span className={styles.command}>dotnet</span><span> add package Stashbox</span><span className={styles.options}> --version</span> 5.12.1<span className={styles.cursor}></span></pre>
<pre><span className={styles.command_start}>{'$'} </span><span className={styles.command}>dotnet</span><span> add package Stashbox</span><span className={styles.options}> --version</span> 5.12.2<span className={styles.cursor}></span></pre>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/Resolution/ResolutionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private bool TryUnwrapTypeFrom(Type wrapped, out Type unwrapped)
? secondaryLifetimeDescriptor
: serviceRegistration.Lifetime;

var expression = !IsOutputLifetimeManageable(serviceRegistration)
var expression = !IsOutputLifetimeManageable(serviceRegistration) || lifetimeDescriptor is EmptyLifetime
? ExpressionBuilder.BuildExpressionForRegistration(serviceRegistration, resolutionContext, typeInformation)
: lifetimeDescriptor.ApplyLifetime(serviceRegistration, resolutionContext, typeInformation);

Expand Down
25 changes: 25 additions & 0 deletions test/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,24 @@ public void DecoratorTests_Compositor_Works()
Assert.NotNull(registration.RegistrationOptions[RegistrationOption.Initializer]);
Assert.Equal(Lifetimes.Singleton, registration.Lifetime);
}

[Fact]
public void DecoratorTests_Compositor_ChildContainer()
{
using var container = new StashboxContainer();

container.RegisterScoped<ITest1, Test1>();
container.RegisterScoped<ITest1, Test11>();
container.RegisterDecorator<ITest1, TestDecorator8>();

var child = container.CreateChildContainer();

child.RegisterInstance<ITest1>(new Test13());

var a = child.Resolve<ITest1>();

Assert.NotEmpty(((TestDecorator8)a).Decoretees);
}

interface IT1 { }

Expand Down Expand Up @@ -1217,6 +1235,11 @@ public Test12(IDep dep)

}
}

class Test13 : ITest1
{
public ITest1 Test { get; }
}

class TestDisp : IDisp
{
Expand Down Expand Up @@ -1345,10 +1368,12 @@ public TestDecorator7(Func<ITest1> test1)

class TestDecorator8 : ITest1
{
public IEnumerable<ITest1> Decoretees { get; }
public ITest1 Test { get; }

public TestDecorator8(IEnumerable<ITest1> test1)
{
Decoretees = test1;
this.Test = test1.First();
}
}
Expand Down

0 comments on commit c415008

Please sign in to comment.