Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13117

Document use of Provider interface at injection point

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 4.2.3
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Let's say I define a bean

      @Bean
      @Scope( "request" )
      static Foo myFoo() {
      ...
      

      and have another

      @Service
      public class MySingletonService {
      ...
      

      that needs the request scoped instance of foo across multiple methods.

      what I'd like to be able to write is something like this

      @Autowired Provider<Foo> fooProvider;
      
      public void myUsesFoo() {
           Foo foo = fooProvider.get();
           ...
      }
      

      to do this currently I am Autowiring ApplicationContext and calling getBean(...). I would like to wire something less flexible and have it work in a "magic" way. meaning I don't write the provider I just request one. I would also like implementing the provider to be easy for unit test purposes.

      as a Note: I'd be ok if Provider was a new interface, or perhaps I could just request any Bean wrapped with Optional or ThreadLocal (or something I haven't thought of).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                xenoterracide Caleb Cushing
                Last updater:
                St├ęphane Nicoll
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  2 years, 42 weeks, 5 days ago