private void SetLifetimeManager(Type lifetimeType, string name, LifetimeManager lifetimeManager)
 {
     if (lifetimeManager.InUse)
     {
         throw new InvalidOperationException(Resources.LifetimeManagerInUse);
     }
     if (lifetimeType.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);
         }
     }
 }
示例#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);
         }
     }
 }
 public void RegisterType(Type from, Type to, LifetimeManager lifetime)
 {
     this.RegisterType(from.ToString(), to.ToString(), lifetime == null ? string.Empty : lifetime.GetType().ToString());
 }