IOC essay
Mr. Xiaobai 2021-06-04 10:15:11

Yes IOC A little bit of learning notes


IOC (Inversion of Control): Inversion of control

DI (Dependency Injection): Dependency injection


1、 Before use IOC How to do it in the case of

stay UserController You need to use UserService To achieve the corresponding function of adding, deleting, modifying and checking , So you need to UserController In the direct new UserService();
For one UserService It's OK for me , If I had several Service Need to use , It's used everywhere new To create an object for your own use ? If I had each Service There are several implementations , Then separate them new? It's too tired .

2、IOC Service Provider On stage

We need to use an object , But I don't want to create it myself , Is there anyone else to help us with the basic work ? And then we focus on the business that we want to focus on ?
Yes , The one who came to help us do this is IOC Service Provider.
When we need something , It's entirely up to it to help us create , It knows what we need .
When we lack something , You can also take the initiative to ask it for , It has what we want .
We give it control of the objects we create , We leave our dependence to it to manage , This is it. ---- Inversion of control \ Dependency injection .

3、IOC Service Provider What is it?

IOC Service Provider It's an abstract concept , It means any kind of will IOC The implementation of binding business objects together in a scenario , It can be a piece of code , It can also be a set of related classes , Or more common IOC Frame or IOC Container implementation .

And what we use Spring, its IOC Container is :

  • BeanFactory: The most basic IOC Service support , Using the delayed initialization strategy .
  • ApplicationContext: stay BeanFactory Build on the basis of , Relatively advanced container implementation , And then there's the event release 、 International support, etc . You can use just in time loading , The container automatically completes the initialization binding after startup .

4、IOC What exactly is the container doing behind it

without doubt , Its two most basic responsibilities are :

  • Business object construction management : Responsible for creating all the required objects in the system
  • Dependency binding between business objects : Organize these created objects and let them work together

5、 How do we use IOC

Have used @Controller @Service @Resource @Autowired These are the notes ?

Please bring the original link to reprint ,thank
Similar articles

2021-08-09

2021-08-09