container icon indicating copy to clipboard operation
container copied to clipboard

Optimize build strategies

Open ENikS opened this issue 6 years ago • 0 comments

Build Strategies

A build strategy is type derived from BuilderStrategy class and represents a processing step during dependency resolution. Unity provides, among other, these built-in strategies:

  • ConstructorProcessor
  • FieldProcessor
  • PropertyProcessor
  • MethodProcessor
  • FactoryProcessor
  • InstanceProcessor

Problem

Current implementation has all strategies added to the same staged chain and executes all of them regardless of type of resolution. For example, instance registrations do not create new instances and do not require constructor, fields, and etc. strategies.

Solution

The Staged Strategy Chain should be split into three chains:

public abstract IDictionary<TStage, TStrategy> TypePipeline { get; }
public abstract IDictionary<TStage, TStrategy> FactoryPipeline { get; }
public abstract IDictionary<TStage, TStrategy> InstancePipeline { get; }

The IStagedStrategyChain is replaced with IDictionary. For more information see #227

Impact

Extension authors should modify code to add their strategies to appropriate chain.

ENikS avatar Dec 20 '19 06:12 ENikS