/// <summary> /// A helper method used by the generated IL to set up a PerResolveLifetimeManager lifetime manager /// if the current object is such. /// </summary> /// <param name="context">Current build context.</param> public static void SetPerBuildSingleton(this IBuilderContext context) { var lifetime = (context ?? throw new ArgumentNullException(nameof(context))).Policies.Get <ILifetimePolicy>(context.BuildKey); if (lifetime is PerResolveLifetimeManager) { var perBuildLifetime = new InternalPerResolveLifetimeManager(context.Existing); context.Policies.Set <ILifetimePolicy>(perBuildLifetime, context.BuildKey); } }
/// <summary> /// A helper method used by the generated IL to set up a PerResolveLifetimeManager lifetime manager /// if the current object is such. /// </summary> /// <param name="context">Current build context.</param> public static void SetPerBuildSingleton(this IBuilderContext context) { var lifetime = (context ?? throw new ArgumentNullException(nameof(context))) .Policies.GetOrDefault(typeof(ILifetimePolicy), context.OriginalBuildKey, out _); if (lifetime is PerResolveLifetimeManager) { var perBuildLifetime = new InternalPerResolveLifetimeManager(context.Existing); context.Policies.Set(context.OriginalBuildKey.Type, context.OriginalBuildKey.Name, typeof(ILifetimePolicy), perBuildLifetime); } }