コード例 #1
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(new ExtensionContextImpl(this), lifetimeManager.GetType());
         policies.Set <ILifetimeFactoryPolicy>(factory, new NamedTypeBuildKey(lifetimeType, name));
     }
     else
     {
         lifetimeManager.InUse = true;
         policies.Set <ILifetimePolicy>(lifetimeManager,
                                        new NamedTypeBuildKey(lifetimeType, name));
         if (lifetimeManager is IDisposable)
         {
             lifetimeContainer.Add(lifetimeManager);
         }
     }
 }
コード例 #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);
         }
     }
 }