Ejemplo n.º 1
0
        /// <summary>
        /// Create a whole new scope with all current's scope registration.
        /// </summary>
        /// <param name="typeRegisterAction">Specific child registration..</param>
        /// <returns>Child scope.</returns>
        public IScope CreateChildScope(Action <ITypeRegister> typeRegisterAction = null)
        {
            Action <ContainerBuilder> act = null;

            if (typeRegisterAction != null)
            {
                var typeRegister = new TypeRegister();
                typeRegisterAction.Invoke(typeRegister);
                act += b => AutofacTools.RegisterContextTypes(b, typeRegister);
            }
            if (act != null)
            {
                return(new AutofacScope(scope.BeginLifetimeScope(act)));
            }
            return(new AutofacScope(scope.BeginLifetimeScope()));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a whole new scope with all current's scope registration.
 /// </summary>
 /// <param name="typeRegisterAction">Specific child registration..</param>
 /// <returns>Child scope.</returns>
 public IScope CreateChildScope(Action <ITypeRegister>?typeRegisterAction = null)
 {
     if (componentContext is ILifetimeScope scope)
     {
         Action <ContainerBuilder>?act = null;
         if (typeRegisterAction != null)
         {
             var typeRegister = new TypeRegister();
             typeRegisterAction.Invoke(typeRegister);
             act += b => AutofacTools.RegisterContextTypes(b, typeRegister);
         }
         if (act != null)
         {
             return(new AutofacScope(scope.BeginLifetimeScope(act)));
         }
         return(new AutofacScope(scope.BeginLifetimeScope()));
     }
     throw new InvalidOperationException("Autofac cannot create a child scope from IComponentContext. Parent scope should be created with the ctor that takes an ILifeTimeScope parameter");
 }