You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public DependencyOverride(Type contractType, ...)
public DependencyOverride(stringcontractName, ...)
public DependencyOverride(Type contractType,string? contractName, ...)
Override by Type
The constructor DependencyOverride(Type contractType, ...) creates an override that matches any dependency with specified `Type' regardless of dependency name. So many of these imports will match the override:
The constructor string contractName creates an override that matches any dependency with specified contractName, regardless of the dependency's Type. So many of these imports will match the override:
Finally, the constructor DependencyOverride(Type contractType, string? contractName, ...) creates an override that matches only dependencies with exact Type and contracts Name.
Problems
The current implementation has several issues:
DependencyOverride creates false positives on targeted overrides
Overrides are not matched to dependencies correctly
Type override only works for "null" name
False positives
During the equality check, the target is ignored. This example illustrates the issue:
A type Service is registered with a container and requested to inject a constructor with the string "data".
During resolution, a DependencyOverride for type 'string' is passed into the Resolve. This override should be applied to every dependency with the type string, but it fails.
The text was updated successfully, but these errors were encountered:
ENikS
transferred this issue from unitycontainer/abstractions
Sep 26, 2020
ENikS
changed the title
DependencyOverride.Equals() creates false positive on targeted overrides
DependencyOverride incorrectly matches dependencies
Nov 5, 2020
ENikS
changed the title
DependencyOverride incorrectly matches dependencies
DependencyOverride incorrect matches
Nov 5, 2020
DependencyOverride
The
DependencyOverride
provides an override for any resolved dependency that matches the contract.Usage
Override is passed to the
Resolve
method alone withType
andName
of the requested contract:Variants
Override by Type
The constructor
DependencyOverride(Type contractType, ...)
creates an override that matches any dependency with specified `Type' regardless of dependency name. So many of these imports will match the override:Override by Name
The constructor
string contractName
creates an override that matches any dependency with specifiedcontractName
, regardless of the dependency'sType.
So many of these imports will match the override:Override by Contract
Finally, the constructor
DependencyOverride(Type contractType, string? contractName, ...)
creates an override that matches only dependencies with exactType
and contractsName
.Problems
The current implementation has several issues:
DependencyOverride
creates false positives on targeted overrides"null"
nameFalse positives
During the equality check, the target is ignored. This example illustrates the issue:
So, during resolution, this override will be applied to either target.
Not matching to dependency
This example illustrates the issue:
A type
Service
is registered with a container and requested to inject a constructor with the string "data".During resolution, a
DependencyOverride
for type 'string' is passed into theResolve
. This override should be applied to every dependency with the typestring
, but it fails.The text was updated successfully, but these errors were encountered: