Added implementation
This commit is contained in:
Родитель
0eebaf0942
Коммит
a612757ec4
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче