title: Can I inject a service into a filter in Grails?
body: <p>I have a service to get and set the user in the session. I would like to pass in some user information to each view if there is a logged in user and thought a filter would be the best way so I don't have to duplicate that in every controller/action. When I run the app, it get this error:</p>
  
  <pre><code>Error creating bean with name 'userService': Scope 'session' is not active for the current thread
  </code></pre>
  
  <p>My filter looks like this:</p>
  
  <pre><code>class SecurityFilters {
      def userService
  
      def filters = {
          setUser(controller:'*', action:'*') {
              before = {
                  if (userService.isLoggedIn()) {
                      request.user = userService.getUser()
                  } else {
                      request.user = null
                  }
              }
          }
      }   
  }
  </code></pre>
  
  <p>I know I can just ultimately access the user through session.user, but I want to be able to call userService.isLoggedIn() which I can't easily through the view. So is there a way to inject the service into the filter, or should I just create a taglib to wrap userService.isLoggedIn()?</p>