private void SetLifetimeManager(Type lifetimeType, string name, LifetimeManager lifetimeManager)
 {
     if (lifetimeManager.InUse)
     {
         throw new InvalidOperationException(Resources.LifetimeManagerInUse);
     }
     if (lifetimeType.GetTypeInfo().IsGenericTypeDefinition)
     {
         LifetimeManagerFactory factory =
             new LifetimeManagerFactory(Context, lifetimeManager.GetType());
         Context.Policies.Set<ILifetimeFactoryPolicy>(factory,
             new NamedTypeBuildKey(lifetimeType, name));
     }
     else
     {
         lifetimeManager.InUse = true;
         Context.Policies.Set<ILifetimePolicy>(lifetimeManager,
             new NamedTypeBuildKey(lifetimeType, name));
         if (lifetimeManager is IDisposable)
         {
             Context.Lifetime.Add(lifetimeManager);
         }
     }
 }
Example #2
0
 private void SetLifetimeManager(Type lifetimeType, string name, LifetimeManager lifetimeManager)
 {
     if (lifetimeManager.InUse)
     {
         throw new InvalidOperationException(Resources.LifetimeManagerInUse);
     }
     if (lifetimeType.GetTypeInfo().IsGenericTypeDefinition)
     {
         LifetimeManagerFactory factory =
             new LifetimeManagerFactory(Context, lifetimeManager.GetType());
         Context.Policies.Set <ILifetimeFactoryPolicy>(factory,
                                                       new NamedTypeBuildKey(lifetimeType, name));
     }
     else
     {
         lifetimeManager.InUse = true;
         Context.Policies.Set <ILifetimePolicy>(lifetimeManager,
                                                new NamedTypeBuildKey(lifetimeType, name));
         if (lifetimeManager is IDisposable)
         {
             Context.Lifetime.Add(lifetimeManager);
         }
     }
 }