container icon indicating copy to clipboard operation
container copied to clipboard

Update FactoryRegistration with ResolveDelegate signature

Open ENikS opened this issue 6 years ago • 0 comments

Description

Original factory delegate had following signature:

object Factory(IUnityContainer container, Type type, string name);

When resolving, this delegate would get a reference to a container and would be passed a type and a name of contract requested. The delegate supposed to create requested instance and return it.

Problem

This type of delegate does not allow passing any overrides as well as it would not account for any Per-Resolve lifetime managers during resolution.

Solution

Unity Container used ResolveDelegate delegates to perform resolutions. This new mechanism supports all build in features of the container and allows overriding of resolved values.

New signature of resolution function should be as follows:

object? resolver(IResolveContext context);

Interface IUnityContainer should be updated accordingly:

IUnityContainer RegisterFactory(Type type, string? name, Func<IResolveContext, object?> factory, IFactoryLifetimeManager? lifetimeManager);

Impact

Legacy registrations will be supported through extension methods.

ENikS avatar Jan 10 '20 19:01 ENikS