Skip to content

Commit

Permalink
Update changelog, add ResolveFactoryOrDefault()
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Mar 2, 2022
1 parent 1015495 commit 1acdd37
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 70 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ 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.2.0] -
### Added
- Null-state analysis by setting the nullable context to `enable`.
- Option to exclude a factory's result from dispose tracking, even if it would be tracked by default. This gives the ability to decide within the factory delegate that the result should be tracked or not.
```cs
.Register<Service>(options => options
.WithFactory<IRequestContext>(requestContext =>
{
var result = new Service();
if (resultShouldBeExcludedFromTracking())
return requestContext.ExcludeFromTracking(new Service());

return result;
})
);
```
- A new `ResolveFactoryOrDefault()` method that allows `null` results.
- A new `ResolveOrDefault()` method that allows `null` results.

### Changed
- `Resolve()` with the `nullResultAllowed` parameter became obsolete, it was replaced by `ResolveOrDefault()`.
- Each `ResolveFactory<>()` method became obsolete as their functionality is equivalent to `Resolve<Func<>>()`.

### Removed
- `nullResultAllowed` parameter of `ResolveFactory()`.

## [v5.1.0] - 2022-02-27
### Changed
- Marked the `.WithRuntimeCircularDependencyTracking()` container configuration option as **Obsolete** in favor of [parameterized factory delegates](https://z4kn4fein.github.io/stashbox/#/usage/advanced-registration?id=consider-this-before-using-the-resolver-parameter-inside-a-factory).
Expand Down
18 changes: 13 additions & 5 deletions src/IDependencyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public interface IDependencyResolver : IServiceProvider,
object Resolve(Type typeFrom, object name, object[]? dependencyOverrides = null);

/// <summary>
/// Resolves an instance from the container or default if the type does not exist.
/// Resolves an instance from the container or returns default if the type is not resolvable.
/// </summary>
/// <param name="typeFrom">The type of the requested instance.</param>
/// <param name="dependencyOverrides">A collection of objects which are used to override certain dependencies of the requested service.</param>
/// <returns>The resolved object.</returns>
object? ResolveOrDefault(Type typeFrom, object[]? dependencyOverrides = null);

/// <summary>
/// Resolves an instance from the container or default if the type does not exist.
/// Resolves an instance from the container or returns default if the type is not resolvable.
/// </summary>
/// <param name="typeFrom">The type of the requested instance.</param>
/// <param name="name">The name of the requested registration.</param>
Expand All @@ -87,14 +87,22 @@ public interface IDependencyResolver : IServiceProvider,
IEnumerable<object> ResolveAll(Type typeFrom, object[]? dependencyOverrides = null);

/// <summary>
/// Returns a factory method that can be used to activate the service.
/// Returns a factory delegate that can be used to activate the service.
/// </summary>
/// <param name="typeFrom">The type of the requested instances.</param>
/// <param name="name">The name of the requested registration.</param>
/// <param name="parameterTypes">The parameter type.</param>
/// <returns>The factory delegate.</returns>
Delegate ResolveFactory(Type typeFrom, object? name = null, params Type[] parameterTypes);

/// <summary>
/// Returns a factory delegate that can be used to activate the service or returns default if the type is not resolvable.
/// </summary>
/// <param name="typeFrom">The type of the requested instances.</param>
/// <param name="name">The name of the requested registration.</param>
/// <param name="nullResultAllowed">If true, the container will return with null instead of throwing <see cref="ResolutionFailedException"/>.</param>
/// <param name="parameterTypes">The parameter type.</param>
/// <returns>The factory delegate.</returns>
Delegate? ResolveFactory(Type typeFrom, object? name = null, bool nullResultAllowed = false, params Type[] parameterTypes);
Delegate? ResolveFactoryOrDefault(Type typeFrom, object? name = null, params Type[] parameterTypes);

/// <summary>
/// Creates a new scope.
Expand Down
4 changes: 2 additions & 2 deletions src/IResolutionScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public interface IResolutionScope : IDependencyResolver
object? Name { get; }

/// <summary>
/// Adds a service for further disposable tracking.
/// Adds a service to dispose tracking.
/// </summary>
/// <param name="disposable">The <see cref="IDisposable"/> object.</param>
/// <returns>The <see cref="IDisposable"/> object.</returns>
object AddDisposableTracking(object disposable);

/// <summary>
/// Adds a service for further disposable tracking.
/// Adds a service to dispose tracking.
/// </summary>
/// <param name="disposable">The <see cref="IDisposable"/> object.</param>
/// <param name="requestContext">The request context.</param>
Expand Down
4 changes: 2 additions & 2 deletions src/Resolution/Extensions/DependencyResolverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static TKey Resolve<TKey>(this IDependencyResolver resolver, object name,
(TKey)resolver.Resolve(typeof(TKey), name, dependencyOverrides);

/// <summary>
/// Resolves an instance from the container or default if the type does not exist.
/// Resolves an instance from the container or returns default if the type is not resolvable.
/// </summary>
/// <typeparam name="TKey">The type of the requested instance.</typeparam>
/// <param name="resolver">The dependency resolver.</param>
Expand All @@ -67,7 +67,7 @@ public static TKey Resolve<TKey>(this IDependencyResolver resolver, object name,
(TKey?)(resolver.ResolveOrDefault(typeof(TKey), name, dependencyOverrides) ?? default(TKey));

/// <summary>
/// Resolves an instance from the container or default if the type does not exist.
/// Resolves an instance from the container or returns default if the type is not resolvable.
/// </summary>
/// <typeparam name="TKey">The type of the requested instance.</typeparam>
/// <param name="resolver">The dependency resolver.</param>
Expand Down
Loading

0 comments on commit 1acdd37

Please sign in to comment.