@@ -68,9 +68,10 @@ public override void PreBuildUp(IBuilderContext context)
6868 additionalInterfacesPolicy != null ? additionalInterfacesPolicy . AdditionalInterfaces : Type . EmptyTypes ;
6969
7070 var enumerable = interceptionBehaviors as IInterceptionBehavior [ ] ?? interceptionBehaviors . ToArray ( ) ;
71- context . Policies . Set (
72- new EffectiveInterceptionBehaviorsPolicy { Behaviors = enumerable } ,
73- context . OriginalBuildKey ) ;
71+ context . Policies . Set ( context . OriginalBuildKey . Type ,
72+ context . OriginalBuildKey . Name ,
73+ typeof ( EffectiveInterceptionBehaviorsPolicy ) ,
74+ new EffectiveInterceptionBehaviorsPolicy { Behaviors = enumerable } ) ;
7475
7576 Type [ ] allAdditionalInterfaces =
7677 Intercept . GetAllAdditionalInterfaces ( enumerable , additionalInterfaces ) ;
@@ -91,14 +92,19 @@ public override void PreBuildUp(IBuilderContext context)
9192 /// <param name="context">Context of the build operation.</param>
9293 public override void PostBuildUp ( IBuilderContext context )
9394 {
94- IInterceptingProxy proxy = ( context ?? throw new ArgumentNullException ( nameof ( context ) ) ) . Existing as IInterceptingProxy ;
95+ IInterceptingProxy proxy =
96+ ( context ?? throw new ArgumentNullException ( nameof ( context ) ) ) . Existing as IInterceptingProxy ;
97+
9598 if ( proxy == null )
9699 {
97100 return ;
98101 }
99102
100- EffectiveInterceptionBehaviorsPolicy effectiveInterceptionBehaviorsPolicy =
101- context . Policies . GetNoDefault < EffectiveInterceptionBehaviorsPolicy > ( context . OriginalBuildKey ) ;
103+ var effectiveInterceptionBehaviorsPolicy =
104+ ( EffectiveInterceptionBehaviorsPolicy ) context . Policies
105+ . Get ( context . OriginalBuildKey . Type ,
106+ context . OriginalBuildKey . Name ,
107+ typeof ( EffectiveInterceptionBehaviorsPolicy ) , out _ ) ;
102108 if ( effectiveInterceptionBehaviorsPolicy == null )
103109 {
104110 return ;
@@ -113,8 +119,8 @@ public override void PostBuildUp(IBuilderContext context)
113119 private static TPolicy FindInterceptionPolicy < TPolicy > ( IBuilderContext context )
114120 where TPolicy : class , IBuilderPolicy
115121 {
116- return context . Policies . Get < TPolicy > ( context . OriginalBuildKey ) ??
117- context . Policies . Get < TPolicy > ( context . OriginalBuildKey . Type ) ;
122+ return ( TPolicy ) context . Policies . GetOrDefault ( typeof ( TPolicy ) , context . OriginalBuildKey , out _ ) ??
123+ ( TPolicy ) context . Policies . GetOrDefault ( typeof ( TPolicy ) , context . OriginalBuildKey . Type , out _ ) ;
118124 }
119125
120126 private class EffectiveInterceptionBehaviorsPolicy : IBuilderPolicy
@@ -167,23 +173,26 @@ private static SelectedConstructor FindNewConstructor(SelectedConstructor origin
167173
168174 public static void SetPolicyForInterceptingType ( IBuilderContext context , Type interceptingType )
169175 {
170- var currentSelectorPolicy = context . Policies . Get < IConstructorSelectorPolicy > ( context . OriginalBuildKey , out var selectorPolicyDestination ) ;
171-
176+ var currentSelectorPolicy =
177+ ( IConstructorSelectorPolicy ) context . Policies . GetOrDefault ( typeof ( IConstructorSelectorPolicy ) ,
178+ context . OriginalBuildKey ,
179+ out var selectorPolicyDestination ) ;
172180 if ( ! ( currentSelectorPolicy is DerivedTypeConstructorSelectorPolicy currentDerivedTypeSelectorPolicy ) )
173181 {
174- selectorPolicyDestination . Set < IConstructorSelectorPolicy > (
175- new DerivedTypeConstructorSelectorPolicy (
176- interceptingType ,
177- currentSelectorPolicy ) ,
178- context . OriginalBuildKey ) ;
182+ selectorPolicyDestination . Set ( context . OriginalBuildKey . Type ,
183+ context . OriginalBuildKey . Name ,
184+ typeof ( IConstructorSelectorPolicy ) ,
185+ new DerivedTypeConstructorSelectorPolicy (
186+ interceptingType , currentSelectorPolicy ) ) ;
179187 }
180188 else if ( currentDerivedTypeSelectorPolicy . _interceptingType != interceptingType )
181189 {
182- selectorPolicyDestination . Set < IConstructorSelectorPolicy > (
183- new DerivedTypeConstructorSelectorPolicy (
184- interceptingType ,
185- currentDerivedTypeSelectorPolicy . _originalConstructorSelectorPolicy ) ,
186- context . OriginalBuildKey ) ;
190+ selectorPolicyDestination . Set ( context . OriginalBuildKey . Type ,
191+ context . OriginalBuildKey . Name ,
192+ typeof ( IConstructorSelectorPolicy ) ,
193+ new DerivedTypeConstructorSelectorPolicy (
194+ interceptingType ,
195+ currentDerivedTypeSelectorPolicy . _originalConstructorSelectorPolicy ) ) ;
187196 }
188197 }
189198 }
0 commit comments