This commit is contained in:
Eugene Sadovoi 2018-03-31 15:50:58 -04:00
Родитель 0eebaf0942
Коммит a612757ec4
2 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -13,9 +13,9 @@ namespace BuildPlanCreatorExample
typeof(FooBuildPlanCreatorPolicy).GetTypeInfo().GetDeclaredMethod(nameof(FactoryMethod));
/// <summary>
///
/// Factory plan to build [I]Foo type
/// </summary>
/// <param name="policies"></param>
/// <param name="policies">Container policy list to store created plans</param>
public FooBuildPlanCreatorPolicy(IPolicyList policies)
{
_policies = policies;
@ -28,12 +28,11 @@ namespace BuildPlanCreatorExample
var factoryMethod =
_factoryMethod.MakeGenericMethod(typeToBuild)
.CreateDelegate(typeof(DynamicBuildPlanMethod));
// Create policy
var creatorPlan = new DynamicMethodBuildPlan((DynamicBuildPlanMethod)factoryMethod);
// Register this policy with container to optimize performance
_policies.Set(buildKey.Type, string.Empty, typeof(IBuildPlanCreatorPolicy), creatorPlan);
// Register BuildPlan policy with the container to optimize performance
_policies.Set(buildKey.Type, string.Empty, typeof(IBuildPlanPolicy), creatorPlan);
return creatorPlan;
}

Просмотреть файл

@ -8,11 +8,12 @@ namespace BuildPlanCreatorExample
protected override void Initialize()
{
// Register policy
// Note name of the registration! It tells Unity that this policy
// applies to ALL resolutions of the type regardless of requested name.
// In other words it creates 'Built-In' registration similar to Lazy or IEnumerable.
Context.Policies.Set(typeof(IFoo<>), string.Empty, typeof(IBuildPlanCreatorPolicy), new FooBuildPlanCreatorPolicy(Context.Policies));
Context.Policies.Set(typeof(Foo<>), string.Empty, typeof(IBuildPlanCreatorPolicy), new FooBuildPlanCreatorPolicy(Context.Policies));
}
}
}