Closed spasarto closed 5 years ago
You have several options here:
ServiceCollection
or Unity registration to create type manuallyIUnityContainer.RegisterType
providing required injection membersIUnityContainer
and use IUnityContainer.Resolve
with appropriate overridesThanks for the reply.
The first two cases address registration overrides, which is a different scenario. The third option requires me to do the resolution, which doesn't work when code I don't control is performing the resolution.
For example, let's say I have a web project, and I register my types normally. However for certain web requests, I want to resolve a different set of dependencies (ie, dryrun/beta implementations/regional cases, etc). Because I don't have access to type resolution, I am stuck resolving whatever I registered. This pushes the burden to all of my implementations to know if they need to handle this other case. I would prefer to pass in a ResolverOverride
to unity's resolution that informs the container to resolve the second set of dependencies, when appropriate.
Hopefully that better explains the need for this customization.
It could be simply done by creating either IBuildPlanCreatorPolicy or IBuildPlanPolicy factories.
These will have access to resolver overrides you want to pass so you could customize resolution to your liking.
Fair point. We can close this issue in favor of those suggestions.
I would like to discuss the possibility of adding the ability to customize type resolution. As of right now, the current implementation of Resolve looks like this:
This works for simple cases, but it doesn't allow us to pass in additional values into the resolution - names or resolver overrides. It may also be nice to respond to resolution errors. For reference, here is the current Unity Resolve method:
One possibility is to add support for
IOptions<ResolutionOptions>
, whereResolutionOptions
looks like this: