Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3101224
Author: Peter Csajtai <[email protected]>
Date:   Fri Jan 20 13:15:35 2023 +0100

    Bump version & update changelog

commit 66dc7a8
Author: Peter Csajtai <[email protected]>
Date:   Fri Jan 20 12:48:43 2023 +0100

    Docs update

commit 9dce215
Author: Peter Csajtai <[email protected]>
Date:   Fri Jan 20 00:56:23 2023 +0100

    Update advanced-registration.md

commit 126af9c
Author: Peter Csajtai <[email protected]>
Date:   Fri Jan 20 00:33:53 2023 +0100

    Update docs / fix defined constants for .net7.0

commit 3d4e21e
Author: Peter Csajtai <[email protected]>
Date:   Thu Jan 19 22:50:56 2023 +0100

    Bump version

commit bd93dee
Author: Peter Csajtai <[email protected]>
Date:   Thu Jan 19 22:49:03 2023 +0100

    Add .net7.0 target framework

commit 5213ef6
Author: Peter Csajtai <[email protected]>
Date:   Thu Jan 19 22:34:33 2023 +0100

    Update Program.cs

commit 842bfae
Author: Peter Csajtai <[email protected]>
Date:   Thu Jan 19 22:27:25 2023 +0100

    Update ILGeneratorExtensions.cs

commit 580e0b2
Author: Peter Csajtai <[email protected]>
Date:   Wed Jan 18 22:09:00 2023 +0100

    Reformat

commit 387fa07
Author: Peter Csajtai <[email protected]>
Date:   Wed Jan 18 20:36:37 2023 +0100

    Introduce TypeCache

commit f00b45d
Author: Peter Csajtai <[email protected]>
Date:   Wed Jan 18 18:33:57 2023 +0100

    New namespace syntax
  • Loading branch information
z4kn4fein committed Jan 20, 2023
1 parent 0541869 commit 7a27f57
Show file tree
Hide file tree
Showing 259 changed files with 24,765 additions and 24,952 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/linux-macOS-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ jobs:
3.1.x
5.0.x
6.0.x
7.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 net6.0 --no-restore
dotnet test test/stashbox.tests.csproj -c Release -f net7.0 --no-restore
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.7.0
5.7.1
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.7.1] - 2023-01-20
### Added
- `net7.0` target framework.

### Changed
- Replaced many `typeof()` calls with static type cache.

## [v5.7.0] - 2022-12-19
### Changed
- `ITenantDistributor` now extends `IStashboxContainer` for easier integration.
Expand Down Expand Up @@ -287,6 +294,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.7.1]: https://github.com/z4kn4fein/stashbox/compare/5.7.0...5.7.1
[v5.7.0]: https://github.com/z4kn4fein/stashbox/compare/5.6.0...5.7.0
[v5.6.0]: https://github.com/z4kn4fein/stashbox/compare/5.5.3...5.6.0
[v5.5.3]: https://github.com/z4kn4fein/stashbox/compare/5.5.2...5.5.3
Expand Down
9 changes: 4 additions & 5 deletions 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.7.0)](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.7.1)](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 All @@ -25,9 +25,9 @@ Github (stable) | NuGet (stable) | Fuget (stable)
- 🔥 Gives fast feedback on registration/resolution issues.

## Supported Platforms

- .NET 4.5 and above
- .NET Core
- .NET 5+
- .NET Standard 2.0+
- .NET Framework 4.5+
- Mono
- Universal Windows Platform
- Xamarin (Android/iOS/Mac)
Expand Down Expand Up @@ -62,7 +62,6 @@ Github (stable) | NuGet (stable) | Fuget (stable)

## Benchmarks
- [Performance](https://github.com/danielpalme/IocPerformance)
- [Feature](http://featuretests.apphb.com/DependencyInjection.html)

<br>

Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test_script:
- dotnet test test\stashbox.tests.csproj -f netcoreapp3.1 -c %configuration% --no-build
- 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

artifacts:
- path: artifacts\Stashbox.*.nupkg
Expand Down
26 changes: 12 additions & 14 deletions docs/docs/advanced/child-containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import CodeDescPanel from '@site/src/components/CodeDescPanel';

# Child containers

With child containers, you can build up parent-child relationships between containers. It means you can have a different subset of services present in a child than the parent container. When a dependency is missing from the child container during a resolution request, the parent will be asked to resolve the missing service. If it's found there, the parent will return only the service's registration, and the resolution request will continue within the child. Also, child registrations with the same [service type](/docs/getting-started/glossary#service-type--implementation-type) will override the parent's services.
With child containers, you can build up parent-child relationships between containers. This means you can have a different subset of services present in a child than in the parent container.

When a dependency is missing from the child container during a resolution request, the parent will be asked to resolve the missing service. If it's found there, the parent will return only the service's registration, and the resolution request will continue with the child. Also, child registrations with the same [service type](/docs/getting-started/glossary#service-type--implementation-type) will override the parent's services.

:::info
Child containers are the foundation of the [ASP.NET Core multi-tenant extension](https://github.com/z4kn4fein/stashbox-extensions-dependencyinjection#multitenant).
:::

## Example

Expand Down Expand Up @@ -60,9 +66,9 @@ You can [re-configure](/docs/configuration/container-configuration) child contai
## Re-building singletons
By default, singletons are instantiated and stored only in those containers that registered them. However, you can enable the re-instantiation of singletons in child containers with the `.WithReBuildSingletonsInChildContainer()` [container configuration option](/docs/configuration/container-configuration#re-build-singletons-in-child-containers).

If it's enabled, all singletons will be re-created within those containers that initiated the resolution request. It means that re-built singletons can use overridden dependencies from child containers.
If it's enabled, all singletons will be re-created in those containers that initiated the resolution request. By this, re-built singletons can use overridden dependencies from child containers.

It does not affect the singletons instantiated in the parent container.
Re-building in child containers does not affect the singletons instantiated in the parent container.

```cs
interface IDependency {}
Expand Down Expand Up @@ -109,22 +115,14 @@ using (var container = new StashboxContainer(options => options.WithReBuildSingl
<CodeDescPanel>
<div>

You can build up a hierarchical tree structure from child containers because they can create other child containers with the `.CreateChildContainer()` method.

:::info
This feature is the core of the [multi-tenant package](https://github.com/z4kn4fein/stashbox-extensions-dependencyinjection#multitenant).
:::
You can build up a hierarchical tree structure from containers by creating more child containers with the `.CreateChildContainer()` method.

</div>
<div>

```cs
using(var child1 = container.CreateChildContainer())
{
using(var child2 = child1.CreateChildContainer())
{
}
}
using var child1 = container.CreateChildContainer();
using var child2 = child1.CreateChildContainer();
```

</div>
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/advanced/special-resolution-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When this [feature](/docs/configuration/container-configuration#unknown-type-res
<Tabs>
<TabItem value="Default" label="Default">

Without a registration configuration, the container can resolve only non-interface and non-abstract unknown types. In this case,
Without a registration configuration, the container can resolve only non-interface and non-abstract unknown types. In the following example,
the container creates an implicit registration for `Dependency` and injects its instance into `Service`.
```cs
class Dependency { }
Expand All @@ -31,7 +31,7 @@ var service = container.Resolve<Service>();
</TabItem>
<TabItem value="With registration configuration" label="With registration configuration">

With a registration configuration, you can control how the individual registrations of the unknown types should behave. You also have the option to react to a service resolution request. In this case, we tell the container that if it finds an unregistered `IDependency` service for the first time, it should be mapped to the `Dependency` implementation and have a singleton lifetime. Next time, when the container is coming across with this service, it will use the registration created at the first request.
With a registration configuration, you can control how an unknown type's individual registration should behave. You can also react to a service resolution request. In the following example, we tell the container that if it finds an unregistered `IDependency` for the first time, that should be mapped to `Dependency` and have a singleton lifetime. Next time, when the container comes across this service, it will use the registration created at the first request.

```cs
interface IDependency { }
Expand Down Expand Up @@ -77,11 +77,11 @@ var person = container.Resolve<Person>();
```

:::note
Unknown reference types will be resolved to `null` only in properties and fields.
Unknown reference types are resolved to `null` only in properties and fields.
:::

## Optional value injection
Stashbox respects the optional value of constructor and method arguments.
Stashbox respects the optional value of each constructor and method argument.

```cs
class Person
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/advanced/wrappers-resolvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TabItem from '@theme/TabItem';

# Wrappers & resolvers

Stashbox uses so-called *Wrapper* and *Resolver* implementations to handle those special resolution requests that none of the [service registrations](/docs/getting-started/glossary#service-registration--registered-service) can fulfill. Functionalities like [wrapper](/docs/advanced/wrappers-resolvers#wrappers) and [unknown type](/docs/advanced/special-resolution-cases#unknown-type-resolution) resolution, [cross-container requests](/docs/advanced/child-containers), [optional](/docs/advanced/special-resolution-cases#optional-value-injection) and [default value](/docs/advanced/special-resolution-cases#default-value-injection) injection are all built with resolvers.
Stashbox uses so-called *Wrapper* and *Resolver* implementations to handle special resolution requests that none of the [service registrations](/docs/getting-started/glossary#service-registration--registered-service) can fulfill. Functionalities like [wrapper](/docs/advanced/wrappers-resolvers#wrappers) and [unknown type](/docs/advanced/special-resolution-cases#unknown-type-resolution) resolution, [cross-container requests](/docs/advanced/child-containers), [optional](/docs/advanced/special-resolution-cases#optional-value-injection) and [default value](/docs/advanced/special-resolution-cases#default-value-injection) injection are all built with resolvers.

## Pre-defined wrappers & resolvers
* `EnumerableWrapper`: Used to resolve a collection of services wrapped in one of the collection interfaces that a .NET `Array` implements. (`IEnumerable<>`, `IList<>`, `ICollection<>`, `IReadOnlyList<>`, `IReadOnlyCollection<>`)
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/configuration/container-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var container = new StashboxContainer(options => options
<CodeDescPanel>
<div>

The **re-configuration** of the container is also supported by calling its `.Configure()` method.
**Re-configuration** of the container is also supported by calling its `.Configure()` method.

</div>
<div>
Expand All @@ -42,7 +42,7 @@ container.Configure(options => options.WithDisposableTransientTracking());


## Default configuration
These features are set or enabled by default:
These features are set by default:

- [Constructor selection](/docs/configuration/container-configuration#constructor-selection): `Rules.ConstructorSelection.PreferMostParameters`
- [Registration behavior](/docs/configuration/container-configuration#registration-behavior): `Rules.RegistrationBehavior.SkipDuplications`
Expand Down
17 changes: 7 additions & 10 deletions docs/docs/configuration/registration-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import TabItem from '@theme/TabItem';

Most of the registration methods have an `Action<TOptions>` parameter, enabling several customization options on the given registration.

Here are three examples that show how the API's usage looks like.
They cover the same functionalities you read about in the [basics](/docs/guides/basics) section,
but achieved with the options API.

Here are three examples that show how the API's usage looks like.
They cover the exact functionalities you've read about in the [basics](/docs/guides/basics) section but are achieved with the options API.

</div>
<div>
Expand All @@ -29,7 +27,7 @@ container.Register<IJob, DbBackup>(options => options
</TabItem>
<TabItem value="Lifetime" label="Lifetime">

In the [Lifetime shortcuts](/docs/guides/basics#lifetime-shortcuts) section, it was mentioned that those methods are only sugars; under the curtain, they are also using this API:
It was mentioned in the [Lifetime shortcuts](/docs/guides/basics#lifetime-shortcuts) section, that those methods are only sugars; under the curtain, they are also using this API:
```cs
container.Register<IJob, DbBackup>(options => options
.WithLifetime(Lifetimes.Singleton));
Expand All @@ -38,7 +36,7 @@ container.Register<IJob, DbBackup>(options => options
</TabItem>
<TabItem value="Instance" label="Instance">

This is an example of how you can register an instance with the options API:
An example of how you can register an instance with the options API:
```cs
container.Register<IJob, DbBackup>(options => options
.WithInstance(new DbBackup()));
Expand All @@ -52,9 +50,8 @@ container.Register<IJob, DbBackup>(options => options
<CodeDescPanel>
<div>

The registration configuration API is fluent, which means all the related option methods can be chained after each other.
This nature enables an easier way of configuring complicated registrations.

The registration configuration API is fluent, which means all option methods can be chained after each other.
This provides an easier way to configure complicated registrations.

</div>
<div>
Expand Down Expand Up @@ -226,7 +223,7 @@ container.Register<ILogger, FileLogger>(options => options
<Tabs>
<TabItem value="ReplaceExisting" label="ReplaceExisting">

Indicates that the container should replace an existing registration with the current one (based on [implementation type](/docs/getting-started/glossary#service-type--implementation-type) and name). If there's no existing registration in place, the actual one will be added to the registration list.
Indicates whether the container should replace an existing registration with the current one (based on [implementation type](/docs/getting-started/glossary#service-type--implementation-type) and name). If there's no existing registration in place, the actual one will be added to the registration list.
```cs
container.Register<ILogger, ConsoleLogger>(options => options
.ReplaceExisting());
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/diagnostics/utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TabItem from '@theme/TabItem';

With the `IsRegistered()` function, you can find out whether a service is registered into the container or not.

It returns `true` only when the container has a registration with the given type (and name). It only checks the actual container's registrations. For every other cases, you should use the `CanResolve()` method.
It returns `true` only when the container has a registration with the given type (and name). It only checks the actual container's registrations. For every cases, you should use the `CanResolve()` method.

</div>
<div>
Expand Down Expand Up @@ -48,13 +48,13 @@ bool isIJobRegistered = container.IsRegistered<IJob>("DbBackup");
<CodeDescPanel>
<div>

There might be cases when rather than finding out that a service is registered, you are more interested in whether it's resolvable from the container's actual state or not.
There might be cases when you are more interested in whether a service is resolvable from the container's actual state rather than finding out whether it's registered.

`CanResolve()` returns `true` only when at least one of the following is true:
- The requested type is registered in the current or one of the parent containers.
- The requested type is a closed generic type and its open generic definition is registered.
- The requested type is a wrapper (`IEnumerable<>`, `Lazy<>`, `Func<>`, `KeyValuePair<,>`, `ReadOnlyKeyValue<,>`, `Metadata<,>`, `ValueTuple<,>`, or `Tuple<,>`) and the underlying type is registered.
- The requested type is not registered but it's resolvable and the [unknown type resolution](/docs/configuration/container-configuration#unknown-type-resolution) is enabled.
- The requested type is a closed generic type, and its open generic definition is registered.
- The requested type is a wrapper (`IEnumerable<>`, `Lazy<>`, `Func<>`, `KeyValuePair<,>`, `ReadOnlyKeyValue<,>`, `Metadata<,>`, `ValueTuple<,>`, or `Tuple<,>`), and the underlying type is registered.
- The requested type is not registered, but it's resolvable, and [unknown type resolution](/docs/configuration/container-configuration#unknown-type-resolution) is enabled.

</div>
<div>
Expand Down
Loading

0 comments on commit 7a27f57

Please sign in to comment.